<?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/"
	xmlns:georss="http://www.georss.org/georss" >

<channel>
	<title>Even the wrong words seem to rhyme &#187; lambda</title>
	<atom:link href="http://www.kevinblake.co.uk/tag/lambda/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kevinblake.co.uk</link>
	<description>a blog-life by Kevin Blake</description>
	<lastBuildDate>Sat, 04 Feb 2012 19:58:55 +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>C# Joins with Linq and Lambdas</title>
		<link>http://www.kevinblake.co.uk/csharp-lamba-joins-in-linq/647/</link>
		<comments>http://www.kevinblake.co.uk/csharp-lamba-joins-in-linq/647/#comments</comments>
		<pubDate>Sat, 08 Aug 2009 12:16:14 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[lambda]]></category>
		<category><![CDATA[linq]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[technology]]></category>

		<guid isPermaLink="false">http://www.kevinblake.co.uk/?p=647</guid>
		<description><![CDATA[I&#8217;m always forgetting the syntax for lambda joins in C#, because I never use them enough and get bored looking for reminders enough that I just revert back my old ways and use the query expression instead. So rather than find a good tutorial and bookmark it, I&#8217;ll post it here instead. By the time [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m always forgetting the syntax for lambda joins in C#, because I never use them enough and get bored looking for reminders enough that I just revert back my old ways and use the query expression instead.  So rather than find a good tutorial and bookmark it, I&#8217;ll post it here instead.  By the time it falls off the front page, I&#8217;ll just about have remembered how to do it without needing this anyway <img src='http://www.kevinblake.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>Query Syntax</strong></p>
<div id="wpshdo_1" class="wp-synhighlighter-outer"><div id="wpshdt_1" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_1"></a><a id="wpshat_1" class="wp-synhighlighter-title" href="#codesyntax_1"  onClick="javascript:wpsh_toggleBlock(1)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_1" onClick="javascript:wpsh_code(1)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_1" onClick="javascript:wpsh_print(1)" title="Print code"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_1" class="wp-synhighlighter-inner" style="display: block;"><pre class="csharp" style="font-family:monospace;">var products <span class="sy0">=</span> from audio <span class="kw1">in</span> DbContext.<span class="me1">DataContext</span>.<span class="me1">ProductAudios</span>
join product <span class="kw1">in</span> DbContext.<span class="me1">DataContext</span>.<span class="me1">ProductAudios</span> on audio.<span class="me1">ProductId</span> equals product.<span class="me1">ProductId</span>
select <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> <span class="br0">&#123;</span> Product <span class="sy0">=</span> product, Audio <span class="sy0">=</span> audio <span class="br0">&#125;</span><span class="sy0">;</span></pre></div></div>
<p><strong>Lambda Syntax</strong></p>
<div id="wpshdo_2" class="wp-synhighlighter-outer"><div id="wpshdt_2" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_2"></a><a id="wpshat_2" class="wp-synhighlighter-title" href="#codesyntax_2"  onClick="javascript:wpsh_toggleBlock(2)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_2" onClick="javascript:wpsh_code(2)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_2" onClick="javascript:wpsh_print(2)" title="Print code"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.kevinblake.co.uk/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_2" class="wp-synhighlighter-inner" style="display: block;"><pre class="csharp" style="font-family:monospace;">var products <span class="sy0">=</span> DbContext.<span class="me1">DataContext</span>.<span class="me1">ProductAudios</span>.<span class="me1">Join</span><span class="br0">&#40;</span>
                DbContext.<span class="me1">DataContext</span>.<span class="me1">Products</span>,
                audio <span class="sy0">=&gt;</span> audio.<span class="me1">ProductId</span>,
                product <span class="sy0">=&gt;</span> product.<span class="me1">ProductId</span>,
                <span class="br0">&#40;</span>audio, product<span class="br0">&#41;</span> <span class="sy0">=&gt;</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> <span class="br0">&#123;</span> Product <span class="sy0">=</span> product, Audio <span class="sy0">=</span> audio <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div>
<p>It might look like more code because of my formatting, but I find the lambda syntax much convenient when chaining queries together with other where&#8217;s and groupby&#8217;s, especially when that might be split across different methods.  It also isolates your join nicely, whereas I find the query syntax will start to get particularly unreadable with more complex queries.</p>
<p>Last but not least, another piece of linq-join-related syntax I&#8217;m finding myself always having to look up a lot is for left outer joins.  Fortunately I always end up at MSDN for that one, so I&#8217;ll just link to it here:<br />
<a href="http://msdn.microsoft.com/en-us/library/bb397895.aspx">How to: Perform Left Outer Joins</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kevinblake.co.uk/csharp-lamba-joins-in-linq/647/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

