<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Linq compiled queries (2 of 2)</title>
	<atom:link href="http://rajanadar.com/2008/06/linq-compiled-queries-2-of-2/feed/" rel="self" type="application/rss+xml" />
	<link>http://rajanadar.com/2008/06/linq-compiled-queries-2-of-2/</link>
	<description>life's good when you relax a BIT</description>
	<pubDate>Wed, 08 Sep 2010 01:07:24 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: mac</title>
		<link>http://rajanadar.com/2008/06/linq-compiled-queries-2-of-2/#comment-7529</link>
		<dc:creator>mac</dc:creator>
		<pubDate>Mon, 30 Aug 2010 01:47:34 +0000</pubDate>
		<guid isPermaLink="false">http://rajanadar.com/?p=17#comment-7529</guid>
		<description>&lt;strong&gt; imac http://homcllx.AUTOPARTSTHAI.INFO/tag/imac+mac+PC/ : PC...&lt;/strong&gt;

imac...</description>
		<content:encoded><![CDATA[<p><strong> imac <a href="http://homcllx.AUTOPARTSTHAI.INFO/tag/imac+mac+PC/" rel="nofollow">http://homcllx.AUTOPARTSTHAI.INFO/tag/imac+mac+PC/</a> : PC&#8230;</strong></p>
<p>imac&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: RUBEN</title>
		<link>http://rajanadar.com/2008/06/linq-compiled-queries-2-of-2/#comment-7484</link>
		<dc:creator>RUBEN</dc:creator>
		<pubDate>Wed, 21 Jul 2010 20:16:46 +0000</pubDate>
		<guid isPermaLink="false">http://rajanadar.com/?p=17#comment-7484</guid>
		<description>&lt;strong&gt;&lt;blockquote&gt;&lt;a href="http://medicamentspot.com/" rel="nofollow"&gt;Medicamentspot.com. Canadian Health&#38;Care.Best quality drugs.Special Internet Prices.No prescription online pharmacy. Low price pills. Buy drugs online&lt;/a&gt;...&lt;/strong&gt;

Buy:Arimidex.Lumigan.Zovirax.Nexium.Mega Hoodia.Human Growth Hormone.Petcam (Metacam) Oral Suspension.Retin-A.Prevacid.Zyban.Synthroid.Accutane.Prednisolone.100% Pure Okinawan Coral Calcium.Actos.Valtrex....</description>
		<content:encoded><![CDATA[<p><strong><br />
<blockquote><a href="http://medicamentspot.com/" rel="nofollow">Medicamentspot.com. Canadian Health&amp;Care.Best quality drugs.Special Internet Prices.No prescription online pharmacy. Low price pills. Buy drugs online</a>&#8230;</p></blockquote>
<p></strong></p>
<p>Buy:Arimidex.Lumigan.Zovirax.Nexium.Mega Hoodia.Human Growth Hormone.Petcam (Metacam) Oral Suspension.Retin-A.Prevacid.Zyban.Synthroid.Accutane.Prednisolone.100% Pure Okinawan Coral Calcium.Actos.Valtrex&#8230;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: AARON</title>
		<link>http://rajanadar.com/2008/06/linq-compiled-queries-2-of-2/#comment-7479</link>
		<dc:creator>AARON</dc:creator>
		<pubDate>Wed, 21 Jul 2010 08:37:49 +0000</pubDate>
		<guid isPermaLink="false">http://rajanadar.com/?p=17#comment-7479</guid>
		<description>&lt;strong&gt;&lt;blockquote&gt;&lt;a href="http://medicamentspot.com/" rel="nofollow"&gt;Medicamentspot.com. Canadian Health&#38;Care.No prescription online pharmacy.Best quality drugs.Special Internet Prices. High quality drugs. Order pills online&lt;/a&gt;...&lt;/strong&gt;

Buy:Benicar.Seroquel.Advair.Amoxicillin.Acomplia.Lasix.Cozaar.Nymphomax.Zetia.SleepWell.Aricept.Lipitor.Ventolin.Female Cialis.Buspar.Prozac.Lipothin.Female Pink Viagra.Zocor.Wellbutrin SR....</description>
		<content:encoded><![CDATA[<p><strong><br />
<blockquote><a href="http://medicamentspot.com/" rel="nofollow">Medicamentspot.com. Canadian Health&amp;Care.No prescription online pharmacy.Best quality drugs.Special Internet Prices. High quality drugs. Order pills online</a>&#8230;</p></blockquote>
<p></strong></p>
<p>Buy:Benicar.Seroquel.Advair.Amoxicillin.Acomplia.Lasix.Cozaar.Nymphomax.Zetia.SleepWell.Aricept.Lipitor.Ventolin.Female Cialis.Buspar.Prozac.Lipothin.Female Pink Viagra.Zocor.Wellbutrin SR&#8230;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Raja Nadar</title>
		<link>http://rajanadar.com/2008/06/linq-compiled-queries-2-of-2/#comment-136</link>
		<dc:creator>Raja Nadar</dc:creator>
		<pubDate>Sat, 29 Nov 2008 04:24:55 +0000</pubDate>
		<guid isPermaLink="false">http://rajanadar.com/?p=17#comment-136</guid>
		<description>thanks for your comments Rick.

i totally agree with your explanation for Point #3. The reason i mentioned about static is that:

i prefer all my Delegates variables in a single class, which can be called multiple times across assemblies.
the reason i make it static, is solely because it will be initialized just once, for the lifetime of the application.
as you explained correctly, if we declare the variables as non-static, then all my consumers need to instantiate the object and then invoke the delegate. And there is just one translation done, till the lifetime of that object. But if 2 different classes consume my delegate, the same translation will be effectively happening twice, when they instantiate the object. 

and the above explanation is just as per what you said,  "declare the delegate as static depends on how you plan to use the class and exactly where and when in your code you anticipate reusing the delegate."

i normally use the delegate across my assemblies, and hence prefer Static ones.</description>
		<content:encoded><![CDATA[<p>thanks for your comments Rick.</p>
<p>i totally agree with your explanation for Point #3. The reason i mentioned about static is that:</p>
<p>i prefer all my Delegates variables in a single class, which can be called multiple times across assemblies.<br />
the reason i make it static, is solely because it will be initialized just once, for the lifetime of the application.<br />
as you explained correctly, if we declare the variables as non-static, then all my consumers need to instantiate the object and then invoke the delegate. And there is just one translation done, till the lifetime of that object. But if 2 different classes consume my delegate, the same translation will be effectively happening twice, when they instantiate the object. </p>
<p>and the above explanation is just as per what you said,  &#8220;declare the delegate as static depends on how you plan to use the class and exactly where and when in your code you anticipate reusing the delegate.&#8221;</p>
<p>i normally use the delegate across my assemblies, and hence prefer Static ones.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rick</title>
		<link>http://rajanadar.com/2008/06/linq-compiled-queries-2-of-2/#comment-135</link>
		<dc:creator>Rick</dc:creator>
		<pubDate>Sat, 29 Nov 2008 02:31:22 +0000</pubDate>
		<guid isPermaLink="false">http://rajanadar.com/?p=17#comment-135</guid>
		<description>This is the best set of posts on CompiledQueries I've found.  Its also better than any LINQ book's explanation.  Thank you! Thank you! Thank you! Thank you! Raja!

I have a question about this sentence:

 "3.  Because we need to reuse the delegate to actually have any performance benefit, static variables/method wrappers are preferred." 

This does not seem logical to me.  A non-static delegate can be reused too, and a developer will get the same performance benefit. 

MyCompiledQueries mcq = new MyCompiledQueries;  
//Non-static delegates are created on the preceding line

mcq.GetAllProductsAuthorizedToBeSoldInACountry(db, 10);
mcq.GetAllProductsAuthorizedToBeSoldInACountry(db, 31);
mcq.GetAllProductsAuthorizedToBeSoldInACountry(db, 7);

The performance benefit  is present for all the invocations GetAllProductsAuthorizedToBeSoldInACountry EVEN IF IT WAS NOT DECLARED STATIC. 

 The "static" keyword just determines what constructs the delegate variable, when it is constructed, and how long the variable lives.  If the delegate is static, then the class's static constructor creates it the first time the class is referenced and the variable will live until the AppDomain dies.  If the delegate is not static then the class's object constructor will create it when an object (e.g. mcq above) is created and it will live until the object is disposed.  

So whether or not you should declare the delegate as static depends on how you plan to use the class and exactly where and when in your code you anticipate reusing the delegate.  But the mere fact that you plan to reuse the delegate is not itself a reason to make the delegate static. 

It is the presence of absence of CompiledQueries.Compile() that determines whether you get a performance benefit when you reuse the delegate, not the presence or absence of "static".</description>
		<content:encoded><![CDATA[<p>This is the best set of posts on CompiledQueries I&#8217;ve found.  Its also better than any LINQ book&#8217;s explanation.  Thank you! Thank you! Thank you! Thank you! Raja!</p>
<p>I have a question about this sentence:</p>
<p> &#8220;3.  Because we need to reuse the delegate to actually have any performance benefit, static variables/method wrappers are preferred.&#8221; </p>
<p>This does not seem logical to me.  A non-static delegate can be reused too, and a developer will get the same performance benefit. </p>
<p>MyCompiledQueries mcq = new MyCompiledQueries;<br />
//Non-static delegates are created on the preceding line</p>
<p>mcq.GetAllProductsAuthorizedToBeSoldInACountry(db, 10);<br />
mcq.GetAllProductsAuthorizedToBeSoldInACountry(db, 31);<br />
mcq.GetAllProductsAuthorizedToBeSoldInACountry(db, 7);</p>
<p>The performance benefit  is present for all the invocations GetAllProductsAuthorizedToBeSoldInACountry EVEN IF IT WAS NOT DECLARED STATIC. </p>
<p> The &#8220;static&#8221; keyword just determines what constructs the delegate variable, when it is constructed, and how long the variable lives.  If the delegate is static, then the class&#8217;s static constructor creates it the first time the class is referenced and the variable will live until the AppDomain dies.  If the delegate is not static then the class&#8217;s object constructor will create it when an object (e.g. mcq above) is created and it will live until the object is disposed.  </p>
<p>So whether or not you should declare the delegate as static depends on how you plan to use the class and exactly where and when in your code you anticipate reusing the delegate.  But the mere fact that you plan to reuse the delegate is not itself a reason to make the delegate static. </p>
<p>It is the presence of absence of CompiledQueries.Compile() that determines whether you get a performance benefit when you reuse the delegate, not the presence or absence of &#8220;static&#8221;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Raja Nadar</title>
		<link>http://rajanadar.com/2008/06/linq-compiled-queries-2-of-2/#comment-54</link>
		<dc:creator>Raja Nadar</dc:creator>
		<pubDate>Thu, 24 Jul 2008 05:30:54 +0000</pubDate>
		<guid isPermaLink="false">http://rajanadar.com/?p=17#comment-54</guid>
		<description>yes it can be turned into a compiled query.. as follows;

var CustomerOrderCompiledQuery 
            = CompiledQuery.Compile((MyDataContext db) =&gt;
               from c in db.Customers
               join o in db.Orders
               on c.CustomerID equals o.CustomerID into do
               from o in do.DefaultIfEmpty()
               select new { c, o }); 

            using (MyDataContext db = new MyDataContext())
            {
                foreach (var customerOrder in CustomerOrderCompiledQuery(db))
                {
                    Console.WriteLine(customerOrder);
                }
            }

note that we have to declare the 'var CustomerOrderCompiledQuery' variable within the scope of its usage for it to remain anonymous..

this is because, we cannot pass an anonymous type to the Func declaration, since we don't know the exact type name at compile time, and Compiled Queries are a compile time thing.

Hence we cannot delare a non-anonymous Expression Type for the Compiled Query variable in a utility class, and use it all across. We need to keep the variable to the scope of its usage.</description>
		<content:encoded><![CDATA[<p>yes it can be turned into a compiled query.. as follows;</p>
<p>var CustomerOrderCompiledQuery<br />
            = CompiledQuery.Compile((MyDataContext db) =><br />
               from c in db.Customers<br />
               join o in db.Orders<br />
               on c.CustomerID equals o.CustomerID into do<br />
               from o in do.DefaultIfEmpty()<br />
               select new { c, o }); </p>
<p>            using (MyDataContext db = new MyDataContext())<br />
            {<br />
                foreach (var customerOrder in CustomerOrderCompiledQuery(db))<br />
                {<br />
                    Console.WriteLine(customerOrder);<br />
                }<br />
            }</p>
<p>note that we have to declare the &#8216;var CustomerOrderCompiledQuery&#8217; variable within the scope of its usage for it to remain anonymous..</p>
<p>this is because, we cannot pass an anonymous type to the Func declaration, since we don&#8217;t know the exact type name at compile time, and Compiled Queries are a compile time thing.</p>
<p>Hence we cannot delare a non-anonymous Expression Type for the Compiled Query variable in a utility class, and use it all across. We need to keep the variable to the scope of its usage.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Luis Fleitas</title>
		<link>http://rajanadar.com/2008/06/linq-compiled-queries-2-of-2/#comment-53</link>
		<dc:creator>Luis Fleitas</dc:creator>
		<pubDate>Wed, 23 Jul 2008 19:44:35 +0000</pubDate>
		<guid isPermaLink="false">http://rajanadar.com/?p=17#comment-53</guid>
		<description>What if I wanted to turn this into a Compiled Query

var q = from c in db.Customers
            join o in db.Orders on c.CustomerID = o.CustomerID into do
            from o in do.DefatultIfEmtpy()
            select new { c, o } 

Can that be turned into a compiled query? How do I pass an anonymous type to the Func declaration?

Thanks</description>
		<content:encoded><![CDATA[<p>What if I wanted to turn this into a Compiled Query</p>
<p>var q = from c in db.Customers<br />
            join o in db.Orders on c.CustomerID = o.CustomerID into do<br />
            from o in do.DefatultIfEmtpy()<br />
            select new { c, o } </p>
<p>Can that be turned into a compiled query? How do I pass an anonymous type to the Func declaration?</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
</channel>
</rss>
