<?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>Powertips &#187; Linq</title>
	<atom:link href="http://scripting.chaindb.com/category/dotnet/linq-dotnet/feed/" rel="self" type="application/rss+xml" />
	<link>http://scripting.chaindb.com</link>
	<description>Programmer tips</description>
	<lastBuildDate>Tue, 15 May 2012 23:56:52 +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 SQL: How to create where IN clause</title>
		<link>http://scripting.chaindb.com/2011/02/28/linq-to-sql-how-to-create-where-in-clause/</link>
		<comments>http://scripting.chaindb.com/2011/02/28/linq-to-sql-how-to-create-where-in-clause/#comments</comments>
		<pubDate>Mon, 28 Feb 2011 08:55:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Linq To SQL]]></category>
		<category><![CDATA[IN]]></category>
		<category><![CDATA[WHERE clause]]></category>

		<guid isPermaLink="false">http://scripting.chaindb.com/?p=942</guid>
		<description><![CDATA[int[] productList = new int[] { 1, 2, 3, 4 }; var myProducts = from p in db.Products where productList.Contains(p.ProductID) select p; SELECT [t0].[ProductID], [t0].[Name], [t0].[ProductNumber], [t0].[MakeFlag], [t0].[FinishedGoodsFlag], [t0].[Color], [t0].[SafetyStockLevel], [t0].[ReorderPoint], [t0].[StandardCost], [t0].[ListPrice], [t0].[Size], [t0].[SizeUnitMeasureCode], [t0].[WeightUnitMeasureCode], [t0].[Weight], [t0].[DaysToManufacture], [t0].[ProductLine], [t0].[Class], [t0].[Style], [t0].[ProductSubcategoryID], [t0].[ProductModelID], [t0].[SellStartDate], [t0].[SellEndDate], [t0].[DiscontinuedDate], [t0].[rowguid], [t0].[ModifiedDate] FROM [Production].[Product] AS [t0] WHERE [t0].[ProductID] IN [...]]]></description>
			<content:encoded><![CDATA[<p><script type="text/javascript"><!--
google_ad_client = "pub-7360303176440694";
/* scripting_468x15, created 5/12/10 */
google_ad_slot = "3352621531";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p>int[] productList = new int[] { 1, 2, 3, 4 };</p>
<p>var myProducts = from p in db.Products<br />
                 where productList.Contains(p.ProductID)<br />
                select p;</p>
<p>SELECT [t0].[ProductID], [t0].[Name], [t0].[ProductNumber], [t0].[MakeFlag], [t0].[FinishedGoodsFlag],<br />
[t0].[Color], [t0].[SafetyStockLevel], [t0].[ReorderPoint], [t0].[StandardCost], [t0].[ListPrice],<br />
[t0].[Size], [t0].[SizeUnitMeasureCode], [t0].[WeightUnitMeasureCode], [t0].[Weight], [t0].[DaysToManufacture],<br />
[t0].[ProductLine], [t0].[Class], [t0].[Style], [t0].[ProductSubcategoryID], [t0].[ProductModelID],<br />
[t0].[SellStartDate], [t0].[SellEndDate], [t0].[DiscontinuedDate], [t0].[rowguid], [t0].[ModifiedDate]<br />
FROM [Production].[Product] AS [t0]<br />
WHERE [t0].[ProductID] IN (@p0, @p1, @p2, @p3)</p>
<p><a href="http://blog.wekeroad.com/2008/02/27/creating-in-queries-with-linq-to-sql">Source</a><br />
<script type="text/javascript"><!--
google_ad_client = "pub-7360303176440694";
/* scripting_Banner (468 x 60) */
google_ad_slot = "0537236933";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://scripting.chaindb.com/2011/02/28/linq-to-sql-how-to-create-where-in-clause/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linq Exception(NullReferenceException): Object reference not set to an instance of an object</title>
		<link>http://scripting.chaindb.com/2010/09/24/linq-exceptionnullreferenceexception-object-reference-not-set-to-an-instance-of-an-object/</link>
		<comments>http://scripting.chaindb.com/2010/09/24/linq-exceptionnullreferenceexception-object-reference-not-set-to-an-instance-of-an-object/#comments</comments>
		<pubDate>Fri, 24 Sep 2010 05:35:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linq]]></category>
		<category><![CDATA[Linq Exceptions]]></category>
		<category><![CDATA[Linq To Object]]></category>
		<category><![CDATA[exception]]></category>
		<category><![CDATA[linq]]></category>
		<category><![CDATA[NullReferece]]></category>
		<category><![CDATA[NullReferenceException]]></category>

		<guid isPermaLink="false">http://scripting.chaindb.com/?p=868</guid>
		<description><![CDATA[With NullReferenceException: &#160;Dim obj As DemographicProperties = Me &#160; &#160; &#160; &#160; &#160; Dim m As IEnumerable&#40;Of DemographicProperty&#41; = From c In obj _ &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;Where &#40;c.MapClass.MapClassID = MapClassID&#41; [...]]]></description>
			<content:encoded><![CDATA[<p><strong>With NullReferenceException:</strong></p>
<div class="geshi no vbnet">
<ol>
<li class="li1">
<div class="de1">&nbsp;<span class="kw6">Dim</span> obj <span class="kw2">As</span> DemographicProperties <span class="sy0">=</span> <span class="kw2">Me</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw6">Dim</span> m <span class="kw2">As</span> IEnumerable<span class="br0">&#40;</span>Of DemographicProperty<span class="br0">&#41;</span> <span class="sy0">=</span> From c In obj _</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Where <span class="br0">&#40;</span>c.<span class="me1">MapClass</span>.<span class="me1">MapClassID</span> <span class="sy0">=</span> MapClassID<span class="br0">&#41;</span> &nbsp;_</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Order By c.<span class="me1">Name</span> Ascending _</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw6">Select</span> c</div>
</li>
</ol>
</div>
<p>If you are getting NullReferenceException, it means the MapClassID is null(nothing in vb.net)</p>
<p><strong>Solve:</strong></p>
<div class="geshi no vbnet">
<ol>
<li class="li1">
<div class="de1">&nbsp;<span class="kw6">Dim</span> obj <span class="kw2">As</span> DemographicProperties <span class="sy0">=</span> <span class="kw2">Me</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw6">Dim</span> m <span class="kw2">As</span> IEnumerable<span class="br0">&#40;</span>Of DemographicProperty<span class="br0">&#41;</span> <span class="sy0">=</span> From c In obj _</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Where <span class="br0">&#40;</span><span class="br0">&#40;</span><span class="kw5">Not</span> c.<span class="me1">MapClass</span> <span class="kw2">Is</span> <span class="kw2">Nothing</span><span class="br0">&#41;</span> <span class="kw2">AndAlso</span> <span class="br0">&#40;</span>c.<span class="me1">MapClass</span>.<span class="me1">MapClassID</span> <span class="sy0">=</span> MapClassID<span class="br0">&#41;</span><span class="br0">&#41;</span> _</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Order By c.<span class="me1">Name</span> Ascending _</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="kw6">Select</span> c</div>
</li>
</ol>
</div>
<p><script type="text/javascript"><!--
google_ad_client = "pub-7360303176440694";
/* scripting_Banner (468 x 60) */
google_ad_slot = "0537236933";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://scripting.chaindb.com/2010/09/24/linq-exceptionnullreferenceexception-object-reference-not-set-to-an-instance-of-an-object/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

