<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Alex Medina &#187; LINQ</title>
	<atom:link href="http://www.alexmedina.net/blog/tag/linq/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.alexmedina.net/blog</link>
	<description>Porque todos los días se aprende algo nuevo...</description>
	<lastBuildDate>Thu, 22 Dec 2011 09:40:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Linq to XML: carga de archivos XML enormes (más de 1Gb)</title>
		<link>http://www.alexmedina.net/blog/2011/10/10/linq-to-xml-carga-de-archivos-xml-enormes-mas-de-1gb/</link>
		<comments>http://www.alexmedina.net/blog/2011/10/10/linq-to-xml-carga-de-archivos-xml-enormes-mas-de-1gb/#comments</comments>
		<pubDate>Mon, 10 Oct 2011 09:39:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[SQLServer]]></category>
		<category><![CDATA[archivos grandes]]></category>
		<category><![CDATA[Linq to XML]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.alexmedina.net/blog/?p=299</guid>
		<description><![CDATA[Estos días he estado bastante liado ya que el proceso que teníamos de carga de XML realizaba una precarga en memoria del archivo (método Load()), la solución que hay es bastante sencilla con un XMLReader, os pongo un fragmento que seguro se entiende: &#160; using (XmlReader reader = XmlReader.Create(directoryTemp + fichero)) { reader.MoveToContent(); int count [...]]]></description>
			<content:encoded><![CDATA[<p>Estos días he estado bastante liado ya que el proceso que teníamos de carga de XML realizaba una precarga en memoria del archivo (método Load()), la solución que hay es bastante sencilla con un XMLReader, os pongo un fragmento que seguro se entiende:</p>
<p>&nbsp;</p>
<pre><span style="color: #339966;">using (XmlReader reader = XmlReader.Create(directoryTemp + fichero))</span>
<span style="color: #339966;">{</span>
<span style="color: #339966;"> reader.MoveToContent();</span>

<span style="color: #339966;"> int count = 0; // una variable contador</span><span style="color: #339966;"> XElement nombretabla = null; // un XElement auxiliar</span>

<span style="color: #339966;"> while (!reader.EOF)</span>
<span style="color: #339966;"> {</span>
<span style="color: #339966;"> switch (reader.NodeType)</span>
<span style="color: #339966;"> {</span>
<span style="color: #339966;"> case XmlNodeType.Element: // se puede filtrar por tipo de XmlNodeType...</span>
<span style="color: #339966;"> if (count == 0)</span>
<span style="color: #339966;"> {</span>
<span style="color: #339966;"> // CUALQUIER CONDICION</span>
<span style="color: #339966;"> count++;</span>
<span style="color: #339966;"> reader.Read();</span>

<span style="color: #339966;"> }</span><span style="color: #339966;"> else if (count == 1)</span>
<span style="color: #339966;"> {</span></pre>
<pre><span style="color: #339966;"> nombretabla = new XElement((XName)reader.Name); // esto para crear un XELEMENT con el nombre del Reader actual</span>
<span style="color: #339966;"> count++;</span>
<span style="color: #339966;"> reader.Read();</span>
<span style="color: #339966;"> }</span><span style="color: #339966;"> else</span>
<span style="color: #339966;"> {</span></pre>
<pre><span style="color: #339966;"> if (string.IsNullOrEmpty(nodoReg)) nodoReg = reader.Name; // condicion para omitir anidados..</span>

<span style="color: #339966;"> if (nodoReg == reader.Name)</span>
<span style="color: #339966;"> {</span>
<span style="color: #339966;"> count++;</span>
<span style="color: #339966;"> nombretabla.Add(XElement.ReadFrom(reader) as XElement);</span>

<span style="color: #339966;"> // INSERCION .. cada X lanzo una inserción en BD</span>
<span style="color: #339966;"> if (count % numInserciones == 0)</span>
<span style="color: #339966;"> {</span>
<span style="color: #339966;"> nombrecondicionado.Add(nombretabla);</span>
<span style="color: #339966;"> docaux.Add(nombrecondicionado);</span>

<span style="color: #339966;"> // VALIDACION ...</span>
<span style="color: #339966;"> validado = ValidarEsquema(docaux, esquema);</span>

<span style="color: #339966;"> if (validado)</span>
<span style="color: #339966;"> {</span>
<span style="color: #339966;"> nreg += cond.Insertar(docaux, delete);</span>
<span style="color: #339966;"> delete = false;</span>

<span style="color: #339966;"> // vacio contenidos</span>
<span style="color: #339966;"> nombretabla.Elements().Remove();</span>
<span style="color: #339966;"> nombrecondicionado.Elements().Remove();</span>
<span style="color: #339966;"> docaux.Elements().Remove();</span>
<span style="color: #339966;"> }</span>
<span style="color: #339966;"> else</span>
<span style="color: #339966;"> {</span>
<span style="color: #339966;"> OnReportInformation(string.Format("ERROR fichero{0} no valido.", fichero), ReportLevel.Error);</span>
<span style="color: #339966;"> EstadoCarga = 2;</span>
<span style="color: #339966;"> }</span>
<span style="color: #339966;"> }</span>

<span style="color: #339966;"> }</span>

<span style="color: #339966;"> }</span>
<span style="color: #339966;"> break;</span>

<span style="color: #339966;"> default :</span>
<span style="color: #339966;"> reader.Read();</span>
<span style="color: #339966;"> break;</span>

<span style="color: #339966;"> }</span>

<span style="color: #339966;"> }</span>
<span style="color: #339966;"> // INSERCION DE LOS ULTIMOS QUE NO ENTRAN EN EL ÚLTIMO WHILE</span>
<span style="color: #339966;"> nombrecondicionado.Add(nombretabla);</span>
<span style="color: #339966;"> docaux.Add(nombrecondicionado);</span>

<span style="color: #339966;"> // VALIDACION</span>
<span style="color: #339966;"> validado = ValidarEsquema(docaux, esquema);</span>

<span style="color: #339966;"> if (validado)</span>
<span style="color: #339966;"> {</span>
<span style="color: #339966;"> nreg += cond.Insertar(docaux, delete);</span>

<span style="color: #339966;"> // vacio contenidos</span>
<span style="color: #339966;"> nombretabla.Elements().Remove();</span>
<span style="color: #339966;"> nombrecondicionado.Elements().Remove();</span>
<span style="color: #339966;"> docaux.Elements().Remove();</span>
<span style="color: #339966;"> }</span>
<span style="color: #339966;"> else</span>
<span style="color: #339966;"> {</span>
<span style="color: #339966;"> OnReportInformation(string.Format("ERROR fichero{0} no valido.", fichero), ReportLevel.Error);</span>
<span style="color: #339966;"> EstadoCarga = 2;</span>
<span style="color: #339966;"> }</span>

<span style="color: #339966;">}</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.alexmedina.net/blog/2011/10/10/linq-to-xml-carga-de-archivos-xml-enormes-mas-de-1gb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linq to XML: Diferencia entre Elements() y Descendants()</title>
		<link>http://www.alexmedina.net/blog/2011/10/10/linq-to-xml-diferencia-entre-elements-y-descendants/</link>
		<comments>http://www.alexmedina.net/blog/2011/10/10/linq-to-xml-diferencia-entre-elements-y-descendants/#comments</comments>
		<pubDate>Mon, 10 Oct 2011 08:55:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[Descendatns]]></category>
		<category><![CDATA[Elements]]></category>
		<category><![CDATA[Linq to XML]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.alexmedina.net/blog/?p=297</guid>
		<description><![CDATA[La diferencia es sencilla, mientra Descendants() cuenta todos los nodos (anidados incluidos), Elements() solo cuenta los del mismo nivel.  string xml = @"                 &#60;Root&#62;                     &#60;Item&#62;                         &#60;id&#62;1&#60;/id&#62;                     &#60;/Item&#62;                     &#60;Item&#62;                         &#60;id&#62;2&#60;/id&#62;                     &#60;/Item&#62;                     &#60;Item&#62;                         &#60;id&#62;3&#60;/id&#62;                         &#60;Items&#62;                             &#60;Item&#62;                                 &#60;id&#62;5&#60;/id&#62;                             &#60;/Item&#62;                             &#60;Item&#62;                                 &#60;id&#62;6&#60;/id&#62;                             &#60;/Item&#62;                           [...]]]></description>
			<content:encoded><![CDATA[<p>La diferencia es sencilla, mientra Descendants() cuenta todos los nodos (anidados incluidos), Elements() solo cuenta los del mismo nivel.</p>
<pre> <span style="color: #339966;">string xml = @"</span>
<span style="color: #339966;">                &lt;Root&gt;</span>
<span style="color: #339966;">                    &lt;Item&gt;</span>
<span style="color: #339966;">                        &lt;id&gt;1&lt;/id&gt;</span>
<span style="color: #339966;">                    &lt;/Item&gt;</span>
<span style="color: #339966;">                    &lt;Item&gt;</span>
<span style="color: #339966;">                        &lt;id&gt;2&lt;/id&gt;</span>
<span style="color: #339966;">                    &lt;/Item&gt;</span>
<span style="color: #339966;">                    &lt;Item&gt;</span>
<span style="color: #339966;">                        &lt;id&gt;3&lt;/id&gt;</span>
<span style="color: #339966;">                        &lt;Items&gt;</span>
<span style="color: #339966;">                            &lt;Item&gt;</span>
<span style="color: #339966;">                                &lt;id&gt;5&lt;/id&gt;</span>
<span style="color: #339966;">                            &lt;/Item&gt;</span>
<span style="color: #339966;">                            &lt;Item&gt;</span>
<span style="color: #339966;">                                &lt;id&gt;6&lt;/id&gt;</span>
<span style="color: #339966;">                            &lt;/Item&gt;                            </span>
<span style="color: #339966;">                        &lt;/Items&gt;</span>
<span style="color: #339966;">                    &lt;/Item&gt;</span>
<span style="color: #339966;">                    &lt;Item&gt;</span>
<span style="color: #339966;">                        &lt;id&gt;4&lt;/id&gt;</span>
<span style="color: #339966;">                    &lt;/Item&gt;</span>
<span style="color: #339966;">                &lt;/Root&gt;";</span>

<span style="color: #339966;">            XDocument doc1 = XDocument.Parse(xml);</span>

<span style="color: #339966;">            var q1 = from e in doc1.Root.Descendants("Item")</span>
<span style="color: #339966;">                     select e;</span>

<span style="color: #339966;">            var q2 = from e in doc1.Root.Elements("Item")</span>
<span style="color: #339966;">                     select e;</span>

<span style="color: #339966;">            int c1 = q1.Count(); //6</span>
<span style="color: #339966;">            int c2 = q2.Count(); //4</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.alexmedina.net/blog/2011/10/10/linq-to-xml-diferencia-entre-elements-y-descendants/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linq to SQL Debug Visualizer, depura facilmente tus consultas LINQ to SQL</title>
		<link>http://www.alexmedina.net/blog/2009/07/01/linq-to-sql-debug-visualizer-depura-facilmente-tus-consultas-linq-to-sql/</link>
		<comments>http://www.alexmedina.net/blog/2009/07/01/linq-to-sql-debug-visualizer-depura-facilmente-tus-consultas-linq-to-sql/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 17:18:42 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[SQLServer]]></category>
		<category><![CDATA[depurar]]></category>
		<category><![CDATA[visual studio]]></category>

		<guid isPermaLink="false">http://alexmedina.net/blog/2009/07/01/linq-to-sql-debug-visualizer-depura-facilmente-tus-consultas-linq-to-sql/</guid>
		<description><![CDATA[Using the LINQ to SQL Debug Visualizer One of the nice development features that LINQ to SQL supports is the ability to use a &#8220;debug visualizer&#8221; to hover over a LINQ expression while in the VS 2008 debugger and inspect the raw SQL that the ORM will ultimately execute at runtime when evaluating the LINQ query [...]]]></description>
			<content:encoded><![CDATA[<h3><font face="arial" size="2"><u>Using the LINQ to SQL Debug Visualizer</u></font></h3>
<p><font face="arial" size="2"> </font><font face="arial" size="2">One of the nice development features that LINQ to SQL supports is the ability to use a &#8220;debug visualizer&#8221; to hover over a LINQ expression while in the VS 2008 debugger and inspect the raw SQL that the ORM will ultimately execute at runtime when evaluating the LINQ query expression.</font></p>
<p><font face="arial" size="2"> </font><font face="arial" size="2">For example, assume we write the below LINQ query expression code against a set of data model classes:</font></p>
<p><font face="arial" size="2"> </font><font face="arial" size="2"><img src="http://www.scottgu.com/blogposts/linqtosql3/step3.jpg" /> </font></p>
<p><font face="arial" size="2"> </font><font face="arial" size="2">We could then use the VS 2008 debugger to hover over the &#8220;products&#8221; variable after the query expression has been assigned:</font></p>
<p><font face="arial" size="2"> </font><font face="arial" size="2"><img src="http://www.scottgu.com/blogposts/linqtosql3/step4.jpg" /> </font></p>
<p><font face="arial" size="2"> </font><font face="arial" size="2">And if we click the small magnifying glass in the expression above, we can launch the LINQ to SQL debug visualizer to inspect the raw SQL that the ORM will execute based on that LINQ query:</font></p>
<p><font face="arial" size="2"> </font><font face="arial" size="2"><img src="http://www.scottgu.com/blogposts/linqtosql3/step5.jpg" /> </font></p>
<p><font face="arial" size="2"> </font><font face="arial" size="2">If you click the &#8220;Execute&#8221; button, you can even test out the SQL query and see the raw returned results that will be returned from the database:</font></p>
<p><font face="arial" size="2"> </font><font face="arial" size="2"><img src="http://www.scottgu.com/blogposts/linqtosql3/step6.jpg" /> </font></p>
<p><font face="arial" size="2"> </font><font face="arial" size="2">This obviously makes it super easy to see precisely what SQL query logic LINQ to SQL ORM is doing for you.  </font></p>
<p><font face="arial" size="2"> </font><font face="arial" size="2">You can learn even more about how all this works by reading the <a href="http://weblogs.asp.net/scottgu/archive/2007/06/29/linq-to-sql-part-3-querying-our-database.aspx" target="_blank">Part 3: Querying our Database</a> segment in my LINQ to SQL series above.</font></p>
<p><font face="arial" size="2"> </font></p>
<h3><font face="arial" size="2"><u>How to Install the LINQ to SQL Debug Visualizer</u></font></h3>
<p><font face="arial" size="2"> </font><font face="arial" size="2">The LINQ to SQL Debug Visualizer isn&#8217;t built-in to VS 2008 &#8211; instead it is an add-in that you need to download to use.  You can download a copy of it <a href="http://www.scottgu.com/blogposts/linqquery/SqlServerQueryVisualizer.zip" target="_blank">here</a>.</font></p>
<p><font face="arial" size="2"> </font><font face="arial" size="2">The download contains both a binary .dll assembly version of the visualizer (within the \bin\debug directory below), as well as all of the source code for the visualizer:</font></p>
<p><font face="arial" size="2"> </font><font face="arial" size="2"><img src="http://www.scottgu.com/blogposts/linqquery/linq1.jpg" /> </font></p>
<p><font face="arial" size="2"> </font><font face="arial" size="2">To install the LINQ to SQL debug visualizer, follow the below steps:</font></p>
<p><font face="arial" size="2"> </font><font face="arial" size="2">1) Shutdown all running versions of Visual Studio 2008 </font></p>
<p><font face="arial" size="2"> </font><font face="arial" size="2">2) Copy the <strong>SqlServerQueryVisualizer.dll</strong> assembly from the <strong>\bin\debug\</strong> directory in the .zip download above into your local <strong>\Program Files\Microsoft Visual Studio 9.0\Common7\Packages\Debugger\Visualizers\</strong> directory:</font></p>
<p><font face="arial" size="2"> </font><font face="arial" size="2"><img src="http://www.scottgu.com/blogposts/linqquery/linq2.jpg" /> </font></p>
<p><font face="arial" size="2"> </font><font face="arial" size="2">3) Start up Visual Studio 2008 again.  Now when you use the debugger with LINQ to SQL you should be able to hover over LINQ query expressions and inspect their raw SQL (no extra registration is required).</font></p>
]]></content:encoded>
			<wfw:commentRss>http://www.alexmedina.net/blog/2009/07/01/linq-to-sql-debug-visualizer-depura-facilmente-tus-consultas-linq-to-sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

