<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>LINQ Cookbook, Recipe 10: Pre-compiling Queries for Performance (Doug Rothaus)</title><link>http://blogs.msdn.com/b/vbteam/archive/2007/11/06/linq-cookbook-recipe-10-pre-compiling-queries-for-performance.aspx</link><description>Ingredients: 
 · Visual Studio 2008 (Beta2 or Higher) 
 
 Categories: LINQ to SQL 
 
 Introduction: 
 As we add cookbook entries, we will include performance improvement tips where appropriate. Here’s a tip that you can use with LINQ to SQL to speed</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: LINQ Cookbook, Recipe 10: Pre-compiling Queries for Performance (Doug Rothaus)</title><link>http://blogs.msdn.com/b/vbteam/archive/2007/11/06/linq-cookbook-recipe-10-pre-compiling-queries-for-performance.aspx#10073227</link><pubDate>Fri, 08 Oct 2010 11:22:55 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10073227</guid><dc:creator>lewcifer</dc:creator><description>&lt;p&gt;Okay I have got this working by making the following changes:&lt;/p&gt;
&lt;p&gt;Return orderQuery(db, pCity)&lt;/p&gt;
&lt;p&gt;End Function&lt;/p&gt;
&lt;p&gt;Call to populate grid is:&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; If lbCity.SelectedValue IsNot Nothing Then&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DataGridView1.DataSource = GetData(lbCity.SelectedValue).ToList()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; End If&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10073227" width="1" height="1"&gt;</description></item><item><title>re: LINQ Cookbook, Recipe 10: Pre-compiling Queries for Performance (Doug Rothaus)</title><link>http://blogs.msdn.com/b/vbteam/archive/2007/11/06/linq-cookbook-recipe-10-pre-compiling-queries-for-performance.aspx#10073152</link><pubDate>Fri, 08 Oct 2010 07:11:59 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10073152</guid><dc:creator>lewcifer</dc:creator><description>&lt;p&gt;Hello&lt;/p&gt;
&lt;p&gt;I am trying to do something similar in order to create a compiled query for reuse and using your code have created the same GetData function and variable using my own data context tables&lt;/p&gt;
&lt;p&gt;Private orderQuery As Func(Of HCADataContext, String, IQueryable(Of T_HCA_Suministro))&lt;/p&gt;
&lt;p&gt;Private Function GetData(ByVal pCity As String) As IQueryable(Of T_HCA_Suministro)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;#39; If the query for orders has not been compiled yet, compile it. Otherwise,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;#39; use the compiled query.&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;If orderQuery Is Nothing Then&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;orderQuery = CompiledQuery.Compile( _&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Function(database As HCADataContext, pLocal As String) _&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;From data In db.T_HCA_Suministro&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Where data.HCAPS_Localidad = pLocal&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Select data)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;#39;From data In db.T_HCA_Suministro&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;#39; &amp;nbsp; &amp;nbsp; &amp;nbsp;Where data.HCAPS_Localidad Is pLocal&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;#39; &amp;nbsp; &amp;nbsp; &amp;nbsp;Select CUPS = data.HCAPS_CUPS, Localidad = data.HCAPS_Localidad, Provincia = data.T_Tipo_Provincias.Pr_Nombre)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;End If&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;#39; Execute the compiled query by calling the ToList method and&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;#39; return the results.&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Return orderQuery(db, pCity).ToList()&lt;/p&gt;
&lt;p&gt;End Function&lt;/p&gt;
&lt;p&gt;Call to populate grid is:&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;If lbCity.SelectedValue IsNot Nothing Then&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;DataGridView1.DataSource = GetData(lbCity.SelectedValue)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;End If&lt;/p&gt;
&lt;p&gt;With the ToList method I am receiving the error:&lt;/p&gt;
&lt;p&gt;No se puede convertir un objeto de tipo &amp;#39;System.Collections.Generic.List`1[LINQ_Test_2.T_HCA_Suministro]&amp;#39; al tipo &amp;#39;System.Linq.IQueryable`1[LINQ_Test_2.T_HCA_Suministro]&amp;#39;.&lt;/p&gt;
&lt;p&gt;If I remove the toList method I receive no error but the data is not displayed in the datagridview even though I can see that the datagridviews datasource contains the correct data.&lt;/p&gt;
&lt;p&gt;Any ideas where I might be going wrong?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10073152" width="1" height="1"&gt;</description></item><item><title>Content Rollup for November and December</title><link>http://blogs.msdn.com/b/vbteam/archive/2007/11/06/linq-cookbook-recipe-10-pre-compiling-queries-for-performance.aspx#6980629</link><pubDate>Fri, 04 Jan 2008 19:04:56 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6980629</guid><dc:creator>Noticias externas</dc:creator><description>&lt;p&gt;Here&amp;amp;#39;s a summary of all the content the VB team members, including myself, have created for you on&lt;/p&gt;
&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=6980629" width="1" height="1"&gt;</description></item><item><title>re: LINQ Cookbook, Recipe 10: Pre-compiling Queries for Performance (Doug Rothaus)</title><link>http://blogs.msdn.com/b/vbteam/archive/2007/11/06/linq-cookbook-recipe-10-pre-compiling-queries-for-performance.aspx#6157616</link><pubDate>Tue, 13 Nov 2007 04:04:46 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6157616</guid><dc:creator>DougR</dc:creator><description>&lt;p&gt;It's not a type-safety issue. It's just syntax. VB doesn't support the second syntax example for jagged arrays.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=6157616" width="1" height="1"&gt;</description></item><item><title>re: LINQ Cookbook, Recipe 10: Pre-compiling Queries for Performance (Doug Rothaus)</title><link>http://blogs.msdn.com/b/vbteam/archive/2007/11/06/linq-cookbook-recipe-10-pre-compiling-queries-for-performance.aspx#6076083</link><pubDate>Sun, 11 Nov 2007 02:53:39 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6076083</guid><dc:creator>Fduch</dc:creator><description>&lt;p&gt;Sorry for offtopic, but... Why are we forced to write&lt;/p&gt;
&lt;p&gt;Dim data As Integer()()() = {New Integer()() {New Integer() {1, 2}, New Integer() {2, 3}}}&lt;/p&gt;
&lt;p&gt;instead of &lt;/p&gt;
&lt;p&gt;Dim data As Integer()()() = {{{1, 2},{2, 3}}}&lt;/p&gt;
&lt;p&gt;Isn't it typesafe?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=6076083" width="1" height="1"&gt;</description></item></channel></rss>