<?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>Codepolice.net &#187; LINQ</title>
	<atom:link href="http://codepolice.net/tag/linq/feed/" rel="self" type="application/rss+xml" />
	<link>http://codepolice.net</link>
	<description>C#, ASP.NET, MVC, LINQ, Wordpress and stuff like that</description>
	<lastBuildDate>Mon, 26 Jul 2010 08:58:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>IN queries with LINQ to SQL</title>
		<link>http://codepolice.net/2010/06/01/in-queries-with-linq-to-sql/</link>
		<comments>http://codepolice.net/2010/06/01/in-queries-with-linq-to-sql/#comments</comments>
		<pubDate>Tue, 01 Jun 2010 13:33:12 +0000</pubDate>
		<dc:creator>Ola</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[in]]></category>
		<category><![CDATA[Linq to sql]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[string array]]></category>

		<guid isPermaLink="false">http://codepolice.net/?p=277</guid>
		<description><![CDATA[This is another awesome feature in LINQ to SQL that i always forget about. Sometimes you have an array of strings or any other type and want to query the database for all values that have one of the values in the array. string platform = "windows&#124;linux"; string[] platformList = platform.Split('&#124;'); itemQuery = from m [...]]]></description>
			<content:encoded><![CDATA[<p>This is another awesome feature in LINQ to SQL that i always forget about. Sometimes you have an array of strings or any other type and want to query the database for all values that have one of the values in the array.</p>
<pre class="brush:c#">string platform = "windows|linux";
string[] platformList = platform.Split('|');
itemQuery = from m in itemQuery
from p in m.PlattformItemRelations
where platformList.Contains(p.Plattform.Text.ToLower())
select m;</pre>
<p>Ain&#8217;t that a beauty? I got this tip from <a href="http://blog.wekeroad.com/2008/02/27/creating-in-queries-with-linq-to-sql/">Ron Connery</a> so all the kudos to him.</p>
]]></content:encoded>
			<wfw:commentRss>http://codepolice.net/2010/06/01/in-queries-with-linq-to-sql/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Create a comma separated list with LINQ in C#</title>
		<link>http://codepolice.net/2010/04/20/create-a-comma-separated-list-with-linq-in-c/</link>
		<comments>http://codepolice.net/2010/04/20/create-a-comma-separated-list-with-linq-in-c/#comments</comments>
		<pubDate>Tue, 20 Apr 2010 13:29:59 +0000</pubDate>
		<dc:creator>Ola</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[string]]></category>

		<guid isPermaLink="false">http://codepolice.net/?p=274</guid>
		<description><![CDATA[For some reason I always forget that you do not do .Join on your actual string array. So i might as well write it down here so i never forget about this again. string mycommalist = string.Join(",", alternatives.Select(x=>x.Item.Name).ToArray())]]></description>
			<content:encoded><![CDATA[<p>For some reason I always forget that you do not do .Join on your actual string array. So i might as well write it down here so i never forget about this again.</p>
<pre class="brush:c#">string mycommalist = string.Join(",", alternatives.Select(x=>x.Item.Name).ToArray())</pre>
]]></content:encoded>
			<wfw:commentRss>http://codepolice.net/2010/04/20/create-a-comma-separated-list-with-linq-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Group By with LINQ</title>
		<link>http://codepolice.net/2008/11/24/linq-group-by/</link>
		<comments>http://codepolice.net/2008/11/24/linq-group-by/#comments</comments>
		<pubDate>Mon, 24 Nov 2008 12:16:58 +0000</pubDate>
		<dc:creator>Ola</dc:creator>
				<category><![CDATA[LINQ]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Group By]]></category>
		<category><![CDATA[Linq to entities]]></category>
		<category><![CDATA[Linq to sql]]></category>

		<guid isPermaLink="false">http://www.codepolice.net/?p=64</guid>
		<description><![CDATA[Today i wanted to do a group by query with LINQ wich is something i never done before. I turned out to be kind of easy. If you just want to group by a single field. &#40;from s in db.CrewStatsSet where s.LogDate &#38;gt;= date1 &#38;amp;&#38;amp; s.LogDate &#38;lt;= date2 &#38;amp;&#38;amp; s.Action == action group s by [...]]]></description>
			<content:encoded><![CDATA[<p>Today i wanted to do a group by query with LINQ wich is something i never done before. I turned out to be kind of easy.</p>
<p>If you just want to group by a single field.</p>
<div class="codecolorer-container csharp twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">from</span> s <span style="color: #0600FF; font-weight: bold;">in</span> db<span style="color: #008000;">.</span><span style="color: #0000FF;">CrewStatsSet</span><br />
<span style="color: #0600FF; font-weight: bold;">where</span> s<span style="color: #008000;">.</span><span style="color: #0000FF;">LogDate</span> <span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;=</span> date1 <span style="color: #008000;">&amp;</span>amp<span style="color: #008000;">;&amp;</span>amp<span style="color: #008000;">;</span> s<span style="color: #008000;">.</span><span style="color: #0000FF;">LogDate</span> <span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;=</span> date2 <span style="color: #008000;">&amp;</span>amp<span style="color: #008000;">;&amp;</span>amp<span style="color: #008000;">;</span> s<span style="color: #008000;">.</span><span style="color: #0000FF;">Action</span> <span style="color: #008000;">==</span> action<br />
group s by s<span style="color: #008000;">.</span><span style="color: #0000FF;">User</span><span style="color: #008000;">.</span><span style="color: #0000FF;">nick</span> into g<br />
orderby g<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> descending<br />
<span style="color: #0600FF; font-weight: bold;">select</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> CrewStatsData<br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; Nick <span style="color: #008000;">=</span> g<span style="color: #008000;">.</span><span style="color: #0000FF;">Key</span>,<br />
&nbsp; &nbsp; Count <span style="color: #008000;">=</span> g<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>,<br />
<span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><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></div></div>
<p>And if you need to group by multiple fields.</p>
<div class="codecolorer-container csharp twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">from</span> s <span style="color: #0600FF; font-weight: bold;">in</span> db<span style="color: #008000;">.</span><span style="color: #0000FF;">CrewStatsSet</span><br />
<span style="color: #0600FF; font-weight: bold;">where</span> s<span style="color: #008000;">.</span><span style="color: #0000FF;">LogDate</span> <span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;=</span> date1 <span style="color: #008000;">&amp;</span>amp<span style="color: #008000;">;&amp;</span>amp<span style="color: #008000;">;</span> s<span style="color: #008000;">.</span><span style="color: #0000FF;">LogDate</span> <span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;=</span> date2 <span style="color: #008000;">&amp;</span>amp<span style="color: #008000;">;&amp;</span>amp<span style="color: #008000;">;</span> s<span style="color: #008000;">.</span><span style="color: #0000FF;">Action</span> <span style="color: #008000;">==</span> action<br />
group s by <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> <span style="color: #008000;">&#123;</span> s<span style="color: #008000;">.</span><span style="color: #0000FF;">User</span><span style="color: #008000;">.</span><span style="color: #0000FF;">nick</span>, s<span style="color: #008000;">.</span><span style="color: #0000FF;">Action</span>, s<span style="color: #008000;">.</span><span style="color: #0000FF;">User</span><span style="color: #008000;">.</span><span style="color: #0000FF;">userID</span> <span style="color: #008000;">&#125;</span> into g<br />
orderby g<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> descending<br />
<span style="color: #0600FF; font-weight: bold;">select</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> CrewStatsData<br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; Nick <span style="color: #008000;">=</span> g<span style="color: #008000;">.</span><span style="color: #0000FF;">Key</span><span style="color: #008000;">.</span><span style="color: #0000FF;">nick</span>,<br />
&nbsp; &nbsp; Count <span style="color: #008000;">=</span> g<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>,<br />
&nbsp; &nbsp; ActionId <span style="color: #008000;">=</span> g<span style="color: #008000;">.</span><span style="color: #0000FF;">Key</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Action</span>,<br />
&nbsp; &nbsp; UserId <span style="color: #008000;">=</span> g<span style="color: #008000;">.</span><span style="color: #0000FF;">Key</span><span style="color: #008000;">.</span><span style="color: #0000FF;">userID</span><br />
<span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><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></div></div>
]]></content:encoded>
			<wfw:commentRss>http://codepolice.net/2008/11/24/linq-group-by/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create a tag cloud with limited amout of tags in ASP.NET and LINQ</title>
		<link>http://codepolice.net/2008/10/14/create-a-tag-cloud-with-limited-amout-of-tags-in-aspnet-and-linq/</link>
		<comments>http://codepolice.net/2008/10/14/create-a-tag-cloud-with-limited-amout-of-tags-in-aspnet-and-linq/#comments</comments>
		<pubDate>Tue, 14 Oct 2008 15:13:12 +0000</pubDate>
		<dc:creator>Ola</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Tag]]></category>
		<category><![CDATA[Tag Cloud]]></category>
		<category><![CDATA[TagCloud]]></category>

		<guid isPermaLink="false">http://www.codepolice.net/?p=24</guid>
		<description><![CDATA[Today i built a Tag cloud for my new site. I found this great article about on how to do it with LINQ and C#. But i missed some features. Especially how to limit the number of tags that was shown. So if you read that article and then have a look at this code [...]]]></description>
			<content:encoded><![CDATA[<p>Today i built a Tag cloud for my new site. I found <a href="http://kosta.apostolou.ca/software-development/how-to-create-a-tagcloud-using-linq-and-aspnet" target="_blank">this great article about on how to do it with LINQ and C#</a>. But i missed some features. Especially how to limit the number of tags that was shown. So if you read that article and then have a look at this code if you have the same problem as me.</p>
<div class="codecolorer-container csharp twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">var tagSummary <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">from</span> ti <span style="color: #0600FF; font-weight: bold;">in</span> db<span style="color: #008000;">.</span><span style="color: #0000FF;">TagItemRelations</span><br />
&nbsp; &nbsp; group ti by ti<span style="color: #008000;">.</span><span style="color: #0000FF;">Tag</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Text</span> into tagGroup<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">select</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; Tag <span style="color: #008000;">=</span> tagGroup<span style="color: #008000;">.</span><span style="color: #0000FF;">Key</span>,<br />
&nbsp; &nbsp; TagFrequency <span style="color: #008000;">=</span> tagGroup<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">OrderByDescending</span><span style="color: #008000;">&#40;</span>x<span style="color: #008000;">=&amp;</span>gt<span style="color: #008000;">;</span>x<span style="color: #008000;">.</span><span style="color: #0000FF;">TagFrequency</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Take</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">20</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
<span style="color: #6666cc; font-weight: bold;">int</span> maxTagFrequency <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">from</span> t <span style="color: #0600FF; font-weight: bold;">in</span> tagSummary <span style="color: #0600FF; font-weight: bold;">select</span> t<span style="color: #008000;">.</span><span style="color: #0000FF;">TagFrequency</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Max</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
var tagCloud <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">from</span> ti <span style="color: #0600FF; font-weight: bold;">in</span> tagSummary<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">select</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> TagCloudItem <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; Tag <span style="color: #008000;">=</span> ti<span style="color: #008000;">.</span><span style="color: #0000FF;">Tag</span>,<br />
&nbsp; &nbsp; Weight <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#41;</span>ti<span style="color: #008000;">.</span><span style="color: #0000FF;">TagFrequency</span> <span style="color: #008000;">/</span> maxTagFrequency <span style="color: #008000;">*</span> <span style="color: #FF0000;">100</span><br />
<span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">OrderBy</span><span style="color: #008000;">&#40;</span>x<span style="color: #008000;">=&amp;</span>gt<span style="color: #008000;">;</span>x<span style="color: #008000;">.</span><span style="color: #0000FF;">Tag</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></div></div>
<p>The main difference between my code and the code in the article is that i have slightly more complex data model (should not matter) and that i make the second query against the &#8220;result&#8221; from the first query. This allow me to first order by popularity and then in alphabetic order.</p>
<p>Please leave a comment if there is any better way to do this or if you have any questions.</p>
]]></content:encoded>
			<wfw:commentRss>http://codepolice.net/2008/10/14/create-a-tag-cloud-with-limited-amout-of-tags-in-aspnet-and-linq/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->