<?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; Tag</title>
	<atom:link href="http://codepolice.net/tag/tag/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>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! -->