<?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>Naresh.Jois &#187; Linq</title>
	<atom:link href="http://www.nareshjois.com/tag/linq/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.nareshjois.com</link>
	<description>Home of a professional developer &#38; a aspiring photographer</description>
	<lastBuildDate>Fri, 03 Feb 2012 16:57:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Using Linq to Find a Control</title>
		<link>http://www.nareshjois.com/2010/10/using-linq-to-find-a-control/</link>
		<comments>http://www.nareshjois.com/2010/10/using-linq-to-find-a-control/#comments</comments>
		<pubDate>Fri, 29 Oct 2010 11:04:04 +0000</pubDate>
		<dc:creator>naresh</dc:creator>
				<category><![CDATA[.net Programming]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Linq]]></category>

		<guid isPermaLink="false">http://www.nareshjois.com/?p=827</guid>
		<description><![CDATA[I think Every one has one time or the other tried to find a control by looping over and find the required control, but we can use Linq to do the same thing. public static class PageExtensions &#123; public static IEnumerable&#60;control&#62; All&#40;this ControlCollection controls&#41; &#123; foreach &#40;Control control in controls&#41; &#123; foreach &#40;Control grandChild in [...]]]></description>
			<content:encoded><![CDATA[<p>I think Every one has one time or the other tried to find a control by looping over and find the required control, but we can use Linq to do the same thing.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:consolas, monaco;"> <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">class</span> PageExtensions
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> IEnumerable<span style="color: #008000;">&lt;</span>control<span style="color: #008000;">&gt;</span> All<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> ControlCollection controls<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>Control control <span style="color: #0600FF; font-weight: bold;">in</span> controls<span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>Control grandChild <span style="color: #0600FF; font-weight: bold;">in</span> control<span style="color: #008000;">.</span><span style="color: #0000FF;">Controls</span><span style="color: #008000;">.</span><span style="color: #0000FF;">All</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                    <span style="color: #0600FF; font-weight: bold;">yield</span> <span style="color: #0600FF; font-weight: bold;">return</span> grandChild<span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #0600FF; font-weight: bold;">yield</span> <span style="color: #0600FF; font-weight: bold;">return</span> control<span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&lt;/</span>control<span style="color: #008000;">&gt;</span></pre></div></div>

<p>Then you can use as a Linq Expression</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:consolas, monaco;">var ctrls <span style="color: #008000;">=</span> controls<span style="color: #008000;">.</span><span style="color: #0000FF;">All</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Where</span><span style="color: #008000;">&#40;</span>c <span style="color: #008000;">=&gt;</span> c<span style="color: #008000;">.</span><span style="color: #0000FF;">GetType</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">==</span> <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>Button<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.nareshjois.com/2010/10/using-linq-to-find-a-control/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>LINQ2SQL RAD with confidence</title>
		<link>http://www.nareshjois.com/2009/01/linq2sql-rad-with-confidence/</link>
		<comments>http://www.nareshjois.com/2009/01/linq2sql-rad-with-confidence/#comments</comments>
		<pubDate>Sat, 24 Jan 2009 07:22:07 +0000</pubDate>
		<dc:creator>naresh</dc:creator>
				<category><![CDATA[.net Programming]]></category>
		<category><![CDATA[Linq]]></category>
		<category><![CDATA[LINQ2SQL]]></category>

		<guid isPermaLink="false">http://www.nareshjois.com/?p=286</guid>
		<description><![CDATA[If you are like me who also does have to done some rapid prototyping and application development, you know how painstaking it is to do setup each wire for even a simple application to work, and you will be working so rapidly that you would have forgotten the column names you have entered in db [...]]]></description>
			<content:encoded><![CDATA[<p>If you are like me who also does have to done some rapid prototyping and application development, you know how painstaking it is to do setup each wire for even a simple application to work, and you will be working so rapidly that you would have forgotten the column names you have entered in db few minutes ago, that fact aside you would still require a large prieces of code which would actually constitute the middle tier of application, but the problem is in RAD you do need a top notch middle tier which would cover all the aspects required, then what ? and add to that the fact that you are so used to working with objects that you have even forgotten how to retrive data just using code or you find the whole connection &#8211; adapter &#8211; dataset thing too outdated and too much work just to retrive one row from db.</p>
<p>Now we know what a middle teir is , its nothing but an ORM which maps objects to data along with addtional functions to manipulate that data, for this there exists good amount of code generators which based on your database would generate all code required which would constitute the core of middle tier, but i always found them to be too cumberome ( may be i am too lazy) , now may be some year and a half ago , i was working on a project which extensively used LINQ for queying objects, instead of writing functions for each thing, till then LINQ has become second nature, and i wonder how i used to to do this when LINQ was not around, same time i started looking web for LINQ and i saw something about DLINQ which is now reffered to as LINQ2SQL, LINQ2SQL does what we need to do the hard way, wire up. Just create a new LINQ2SQL class in your project and drag the tables from Server Explorer and voila , you have your midddle tier ready (well not exactly) , it creates classes for each of the table in the db along with associations for relations ,  (eg : If i have a students table in it creates a student class with each column in student as a property, and if you have something like SectionId in Student which links to the section table you can access the linked section by just using Student.Section). Everything becomes so simple from here on, atleast for RAD, It also creates functions for SPs,</p>
<p>The only problem i have with this till date is it works only with SQL Server (I have been able to get it working with SQLCE &#8211; If  this only worked with MySQL) and some things like serialization doesn&#8217;t happen the way i want it to , but anyway this is a tool which you have to use once to get know its usefullness.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nareshjois.com/2009/01/linq2sql-rad-with-confidence/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to make Linq distinct work for you</title>
		<link>http://www.nareshjois.com/2008/11/how-to-make-linq-distinct-work-for-you/</link>
		<comments>http://www.nareshjois.com/2008/11/how-to-make-linq-distinct-work-for-you/#comments</comments>
		<pubDate>Fri, 28 Nov 2008 10:28:32 +0000</pubDate>
		<dc:creator>naresh</dc:creator>
				<category><![CDATA[.net Programming]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Linq]]></category>

		<guid isPermaLink="false">http://www.nareshjois.com/?p=6</guid>
		<description><![CDATA[Have you even tried using linq on your objects then wanted to a distinct but couldn&#8217;t ?, Heres why this does not happen, .net doesn&#8217;t know how to distinguish between two custome objects (even though this looks obvious in most of the cases), So what should we do ? You have to exted the IEqualityComparer [...]]]></description>
			<content:encoded><![CDATA[<p>Have you even tried using linq on your objects then wanted to a distinct but couldn&#8217;t ?, Heres why this does not happen, .net doesn&#8217;t know how to distinguish between two custome objects (even though this looks obvious in most of the cases), So what should we do ?</p>
<p>You have to exted the IEqualityComparer with a custom extension which would allow you to compare your custom objects</p>
<p>Though mine is simple, I am sure that you will make more use of this than me</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:consolas, monaco;">    <span style="color: #6666cc; font-weight: bold;">class</span> Comparer <span style="color: #008000;">:</span> IEqualityComparer<span style="color: #008000;">&lt;</span>GridDetails<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">bool</span> Equals<span style="color: #008000;">&#40;</span>GridDetails x, GridDetails y<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> x<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span> <span style="color: #008000;">==</span> y<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> GetHashCode<span style="color: #008000;">&#40;</span>GridDetails obj<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> obj<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetHashCode</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span></pre></div></div>

<p>An Example usage would be :</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:consolas, monaco;"><span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">grid</span><span style="color: #008000;">.</span><span style="color: #0000FF;">DataSource</span> <span style="color: #008000;">=</span> data<span style="color: #008000;">.</span><span style="color: #0000FF;">ToList</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Distinct</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> Aptra<span style="color: #008000;">.</span><span style="color: #0000FF;">Profile</span><span style="color: #008000;">.</span><span style="color: #0000FF;">BO</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Comparer</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.nareshjois.com/2008/11/how-to-make-linq-distinct-work-for-you/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

