<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-134352470375907644</id><updated>2010-07-26T09:35:46.949-07:00</updated><title type='text'>Ahmad's Blog</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://www.adnanahmad.net/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/134352470375907644/posts/default?orderby=updated'/><link rel='alternate' type='text/html' href='http://www.adnanahmad.net/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Adnan Ahmad</name><uri>http://www.blogger.com/profile/01008287176974220401</uri><email>blog@adnanahmad.net</email></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>7</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-134352470375907644.post-5702445652320783355</id><published>2010-04-27T21:45:00.000-07:00</published><updated>2010-04-28T09:29:55.915-07:00</updated><title type='text'>My Office Space</title><content type='html'>&lt;a href="http://4.bp.blogspot.com/_N5aAiuG68RA/S9e9dJOyexI/AAAAAAAAAZA/2-BzVXTonrY/s1600/OfficeCabinets.jpg"&gt;&lt;img alt="" style="TEXT-ALIGN: center; MARGIN: 0px auto 10px; WIDTH: 400px; DISPLAY: block; HEIGHT: 290px; CURSOR: hand" id="BLOGGER_PHOTO_ID_5465225187494283442" src="http://4.bp.blogspot.com/_N5aAiuG68RA/S9e9dJOyexI/AAAAAAAAAZA/2-BzVXTonrY/s400/OfficeCabinets.jpg" /&gt;&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_N5aAiuG68RA/S9hhWh4dSLI/AAAAAAAAAZI/QknGSnVJL1U/s1600/IMG_1093.JPG"&gt;&lt;img style="TEXT-ALIGN: center; MARGIN: 0px auto 10px; WIDTH: 400px; DISPLAY: block; HEIGHT: 290px; CURSOR: hand" id="BLOGGER_PHOTO_ID_5465225187494283442" border="0" alt="" src="http://2.bp.blogspot.com/_N5aAiuG68RA/S9hhWh4dSLI/AAAAAAAAAZI/QknGSnVJL1U/s400/IMG_1093.JPG" /&gt;&lt;br /&gt;&lt;/a&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;span&gt;&lt;p&gt;&lt;br /&gt;Finally, after weeks of work and patience, our home office workstation and cabinets are finally ready. Here is a picture of the workstation we had been planning for months. It has all finally paid off. The wife and I are extremely pleased with the results. Although we envisioned a very plain looking wood with a solid color in the beginning, the contractor assured us that this would look better and boy was he right!&lt;br /&gt;&lt;br /&gt;If you like the picture, thank you! It was taken using my little Canon PowerShot SX110IS. And, yes that is my 7 month old son Zain in the picture.&lt;br /&gt;&lt;br /&gt;Enjoy and come over to check it out if you gots some time!&lt;br /&gt;&lt;/p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/134352470375907644-5702445652320783355?l=www.adnanahmad.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.adnanahmad.net/feeds/5702445652320783355/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.adnanahmad.net/2010/04/my-office-space_27.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/134352470375907644/posts/default/5702445652320783355'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/134352470375907644/posts/default/5702445652320783355'/><link rel='alternate' type='text/html' href='http://www.adnanahmad.net/2010/04/my-office-space_27.html' title='My Office Space'/><author><name>Adnan Ahmad</name><uri>http://www.blogger.com/profile/01008287176974220401</uri><email>blog@adnanahmad.net</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='13175912509193909219'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_N5aAiuG68RA/S9e9dJOyexI/AAAAAAAAAZA/2-BzVXTonrY/s72-c/OfficeCabinets.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-134352470375907644.post-5220567185686154496</id><published>2010-04-04T13:36:00.001-07:00</published><updated>2010-04-04T13:36:20.541-07:00</updated><title type='text'>The 5 Minute Introduction to Islam</title><content type='html'>&lt;span xmlns=''&gt;&lt;p&gt;I have been asked a number of questions from friends and even strangers about Islam and what it is. I was a bit surprised to know that even the religious people I met, who read Christian literature had little or no idea about Islam. So when I explained to them the basics they seem quite surprised too that if it is so simple then how is it that they never learnt of it before. Let me give a brief introduction for my friends who are curious or just don't know much about Islam.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Islam is a very simple religion which is easy enough to be understood even by a first grader, let alone a fifth grader and yet, it is rich enough for the most intellectuals to spend their lives learning it. Islam is the name of a way of life and it is not an 'ism or an 'ity which is usually associating yourself with an individual, place or an ideology. The word Islam does not refer to any historic person, place or ideology. It means peace and submission (to God). So if I want to submit my will to God I enter Islam. It is not a prepackaged ideology or way of doing things that have been defined by someone. It is a way of thinking and living. There are a set of laws but those are not the essence of Islam. The essence of Islam is in the heart and mind first. Only by following those laws one does not become a Muslim unlike other ideologies where following the practices of the group makes you one. For example, I can spend money, invest, create, buy and sell merchandise and be called a capitalist. There is nothing more required. For Islam it has to begin in the heart and mind. Notice how I mention 'mind' along with heart. It is not blind faith either, where just having faith or believing certain concepts is enough without any logical explanation that the mind can accept. The mind must grasp the concept and the heart must feel its presence for one to be in Islam and called a Muslim.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;So what is it that one must understand and believe? That there is no God but Allah and He is the one and only one with no partners, children, parents or siblings. That's it! If you believe that with your heart, mind and body you are almost in Islam. The second part is the belief and understanding that Allah sends messengers and prophets with revelations to humanity to remind them of Allah and what He wants from them. These messengers include Adam, Noah, Abraham, Moses, Jesus, etc… until Mohammad (peace be upon them). So belief in Allah and His final messenger Mohammad is the basic tenet of Islam. After that everything just falls in place. The rest is a list of pillars or tenets that Islam is structured around. I will describe them briefly in no particular order.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;First is &lt;em&gt;Salaat&lt;/em&gt;, which means prayer. Establishing a regular prayer routine five times a day is the first step one takes when one enters Islam and that is where the man or woman engages in direct dialogue with Allah. You may say, "Dialog?? How can it be a dialog when it is only me speaking? Don't you mean monologue?" No, I mean dialog and let me explain why I say dialog. During the prayer, one reads and recites prayers that one asks of God, like to guide them, to forgive them, to help them etc. This is the part where man communicates to Allah. Then the prayee reads verses from the Quran which is the actual word of Allah written in first person talking directly to you the reader.  So the reciter reads it and ponders over its meaning, fulfilling the other half of the conversation. Performing this multiple times a day keeps one in remembrance of Allah, the one who created him and the reason why he is here. Then the prayer gives him an opportunity to say whatever he wants to Allah to his heart's content. There is no limit to the length and things one can say during prayer although there is a structure and minimum requirement.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;This is already 80% of Islam. So if you understand so far, you have gotten the idea and you can comfortably say you know most of Islam. The remaining pillars are &lt;em&gt;Sawm&lt;/em&gt; (fasting), &lt;em&gt;Zakat&lt;/em&gt; (alms giving), and &lt;em&gt;Hajj&lt;/em&gt; (Pilgrimage). These are not obligatory on everyone but only on those who are able to perform them. Like fasting which is abstaining from food and drink for a set number of days yearly from morning till sunset. It is for those who are able to do it and not for the sick or traveller. Next is the Zakat which is giving charity. If one has in his savings, money that is over a certain amount for over a year he is required to pay 2.5% charity from it. There is no maximum and it is only for those who have at least that certain amount of money sitting around in savings. The last pillar is Hajj which is the pilgrimage to Allah's house in Mecca. This is required only once in a lifetime and for those who are physically capable and can afford the journey. Going to pilgrimage and visiting Allah's symbolic house is a ritual that has the training one requires to be closer to Allah and start his journey back to Allah. &lt;br /&gt;&lt;/p&gt;&lt;p&gt;We are almost done. The rest is belief in the unseen which include the day of resurrection, the books of Allah including the Quran,  the angels, heaven and hell, the jinn and the accountability of one's deeds in front of Allah and reward and punishment. These require no explanation to most of the readers I hope. &lt;br /&gt;&lt;/p&gt;&lt;p&gt;That is all there is to know about Islam. If you can say you know this you can be confident you know Islam and you can spend the rest of the time learning about each of these aspects and reading the Quran to understand what is it that Allah wants from us in this world. That is a journey that only ends when one reaches death. So hope you enjoyed this short introduction and if you agree and believe in these points then all you need to do is take the &lt;em&gt;Shahadah&lt;/em&gt;, which is the declaration of this belief in front of any Muslim to begin your journey towards Allah.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt; &lt;/p&gt;&lt;p&gt;&lt;br /&gt; &lt;/p&gt;&lt;p&gt;&lt;br /&gt; &lt;/p&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/134352470375907644-5220567185686154496?l=www.adnanahmad.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.adnanahmad.net/feeds/5220567185686154496/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.adnanahmad.net/2010/04/5-minute-introduction-to-islam.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/134352470375907644/posts/default/5220567185686154496'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/134352470375907644/posts/default/5220567185686154496'/><link rel='alternate' type='text/html' href='http://www.adnanahmad.net/2010/04/5-minute-introduction-to-islam.html' title='The 5 Minute Introduction to Islam'/><author><name>Adnan Ahmad</name><uri>http://www.blogger.com/profile/01008287176974220401</uri><email>blog@adnanahmad.net</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='13175912509193909219'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-134352470375907644.post-6689647747430940458</id><published>2009-07-04T16:23:00.001-07:00</published><updated>2009-07-04T16:25:58.119-07:00</updated><title type='text'>Simple Tag Cloud Implementation for ASP.NET MVC</title><content type='html'>&lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;I read this &lt;a href="http://www.mikesdotnetting.com/Article.aspx?ArticleID=107"&gt;post&lt;/a&gt; by Mikesdotnetting a few days ago when I was trying to implement a Tag Cloud for our open source forum project &lt;a href="http://www.subforum.net"&gt;SubForum&lt;/a&gt;. Although it was a good post and got me started on how to do it, I found it a bit complex for what I needed. One of the complications that I saw was obviously the Entity Framework and the data layer that Mike talked about to build the Tag Cloud. The data I needed was quite simple and didn’t need to be that complex.&lt;/p&gt;  &lt;p&gt;I decided to implement a simple ASP.NET MVC Tag Cloud using plain SQL and a simple table structure. Also, I did not want categories. I just wanted posts and post tags, so that my Tag Cloud could more accurately represent the Tags in the posts.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;RenderAction Approach&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;I decided to use the RenderAction approach introduced in the &lt;a href="http://aspnet.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=24471#DownloadId=61773"&gt;MVC Futures&lt;/a&gt; library. This helped me strongly type the Tag Cloud partial view to a Model and a specific action in the Controller that populates the model. This is helpful because the Model for the main page is different from the Model for the TagCloud and I wanted to avoid adding the Tag Cloud model to the ViewData collection as a dictionary value. You can read Jimmy Bogard’s &lt;a href="http://www.lostechies.com/blogs/jimmy_bogard/archive/2009/06/18/the-filter-viewdata-anti-pattern.aspx"&gt;post&lt;/a&gt; for more about the benefits of RenderAction.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;The Steps&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Back to the Tag Cloud. Let me start with the Database model:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_N5aAiuG68RA/Sk_kVMswLKI/AAAAAAAAAYQ/aaYZP-Zuv2Y/s1600-h/image11.png"&gt;&lt;img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="211" alt="image" src="http://lh5.ggpht.com/_N5aAiuG68RA/Sk_kVYF4tiI/AAAAAAAAAYU/ItvKojo0nKw/image_thumb7.png?imgmax=800" width="494" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;The Post and Tag object are used to represent a Post and a List of Tags:&lt;/p&gt;  &lt;pre class="csharpcode"&gt; &lt;a href="http://lh6.ggpht.com/_N5aAiuG68RA/Sk_kVw4HWRI/AAAAAAAAAYY/cpWtEkop4dM/s1600-h/image16.png"&gt;&lt;img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="420" alt="image" src="http://lh6.ggpht.com/_N5aAiuG68RA/Sk_kWPhGMLI/AAAAAAAAAYc/KyPhLCLoYlE/image_thumb10.png?imgmax=800" width="408" border="0" /&gt;&lt;/a&gt; &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The way it works is that every time a post is added, the comma separated tags associated with it are taken and inserted as individual tags in the PostTags table.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;We need to pull all the information from the database to perform our Tag Cloud calculations. We need the number of times each tag occurs in the system, the Tag itself and the total number of posts in the system. We can pull all this information in one simple query:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;  &lt;pre&gt;&lt;a style="color: #0000ff" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;amp;siteid=us%2Fdev&amp;amp;p=1&amp;amp;nq=NEW&amp;amp;qu=Select&amp;amp;IntlSearch=&amp;amp;boolean=PHRASE&amp;amp;ig=01&amp;amp;i=09&amp;amp;i=99"&gt;Select&lt;/a&gt; &lt;a style="color: #0000ff" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;amp;siteid=us%2Fdev&amp;amp;p=1&amp;amp;nq=NEW&amp;amp;qu=Count&amp;amp;IntlSearch=&amp;amp;boolean=PHRASE&amp;amp;ig=01&amp;amp;i=09&amp;amp;i=99"&gt;Count&lt;/a&gt;(1) &lt;a style="color: #0000ff" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;amp;siteid=us%2Fdev&amp;amp;p=1&amp;amp;nq=NEW&amp;amp;qu=As&amp;amp;IntlSearch=&amp;amp;boolean=PHRASE&amp;amp;ig=01&amp;amp;i=09&amp;amp;i=99"&gt;As&lt;/a&gt; &lt;a style="color: #0000ff" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;amp;siteid=us%2Fdev&amp;amp;p=1&amp;amp;nq=NEW&amp;amp;qu=Count&amp;amp;IntlSearch=&amp;amp;boolean=PHRASE&amp;amp;ig=01&amp;amp;i=09&amp;amp;i=99"&gt;Count&lt;/a&gt;, PostTags.Tag &lt;a style="color: #0000ff" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;amp;siteid=us%2Fdev&amp;amp;p=1&amp;amp;nq=NEW&amp;amp;qu=As&amp;amp;IntlSearch=&amp;amp;boolean=PHRASE&amp;amp;ig=01&amp;amp;i=09&amp;amp;i=99"&gt;As&lt;/a&gt; Tag, (&lt;a style="color: #0000ff" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;amp;siteid=us%2Fdev&amp;amp;p=1&amp;amp;nq=NEW&amp;amp;qu=Select&amp;amp;IntlSearch=&amp;amp;boolean=PHRASE&amp;amp;ig=01&amp;amp;i=09&amp;amp;i=99"&gt;Select&lt;/a&gt; &lt;a style="color: #0000ff" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;amp;siteid=us%2Fdev&amp;amp;p=1&amp;amp;nq=NEW&amp;amp;qu=Count&amp;amp;IntlSearch=&amp;amp;boolean=PHRASE&amp;amp;ig=01&amp;amp;i=09&amp;amp;i=99"&gt;Count&lt;/a&gt;(*)&lt;br /&gt;  &lt;a style="color: #0000ff" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;amp;siteid=us%2Fdev&amp;amp;p=1&amp;amp;nq=NEW&amp;amp;qu=From&amp;amp;IntlSearch=&amp;amp;boolean=PHRASE&amp;amp;ig=01&amp;amp;i=09&amp;amp;i=99"&gt;From&lt;/a&gt; Posts) &lt;a style="color: #0000ff" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;amp;siteid=us%2Fdev&amp;amp;p=1&amp;amp;nq=NEW&amp;amp;qu=As&amp;amp;IntlSearch=&amp;amp;boolean=PHRASE&amp;amp;ig=01&amp;amp;i=09&amp;amp;i=99"&gt;As&lt;/a&gt; TotalPosts&lt;br /&gt;  &lt;a style="color: #0000ff" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;amp;siteid=us%2Fdev&amp;amp;p=1&amp;amp;nq=NEW&amp;amp;qu=From&amp;amp;IntlSearch=&amp;amp;boolean=PHRASE&amp;amp;ig=01&amp;amp;i=09&amp;amp;i=99"&gt;From&lt;/a&gt; PostTags&lt;br /&gt;&lt;a style="color: #0000ff" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;amp;siteid=us%2Fdev&amp;amp;p=1&amp;amp;nq=NEW&amp;amp;qu=Group&amp;amp;IntlSearch=&amp;amp;boolean=PHRASE&amp;amp;ig=01&amp;amp;i=09&amp;amp;i=99"&gt;Group&lt;/a&gt; &lt;a style="color: #0000ff" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;amp;siteid=us%2Fdev&amp;amp;p=1&amp;amp;nq=NEW&amp;amp;qu=By&amp;amp;IntlSearch=&amp;amp;boolean=PHRASE&amp;amp;ig=01&amp;amp;i=09&amp;amp;i=99"&gt;By&lt;/a&gt; PostTags.Tag&lt;br /&gt;&lt;a style="color: #0000ff" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;amp;siteid=us%2Fdev&amp;amp;p=1&amp;amp;nq=NEW&amp;amp;qu=Order&amp;amp;IntlSearch=&amp;amp;boolean=PHRASE&amp;amp;ig=01&amp;amp;i=09&amp;amp;i=99"&gt;Order&lt;/a&gt; &lt;a style="color: #0000ff" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;amp;siteid=us%2Fdev&amp;amp;p=1&amp;amp;nq=NEW&amp;amp;qu=By&amp;amp;IntlSearch=&amp;amp;boolean=PHRASE&amp;amp;ig=01&amp;amp;i=09&amp;amp;i=99"&gt;By&lt;/a&gt; '&lt;span style="color: #8b0000"&gt;Count&lt;/span&gt;' &lt;a style="color: #0000ff" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;amp;siteid=us%2Fdev&amp;amp;p=1&amp;amp;nq=NEW&amp;amp;qu=Desc&amp;amp;IntlSearch=&amp;amp;boolean=PHRASE&amp;amp;ig=01&amp;amp;i=09&amp;amp;i=99"&gt;Desc&lt;/a&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;!-- .csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } --&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The result of executing this query against our test database returns:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://lh6.ggpht.com/_N5aAiuG68RA/Sk_kWfxBCdI/AAAAAAAAAYg/ziFyAJz4WAY/s1600-h/image21.png"&gt;&lt;img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="206" alt="image" src="http://lh5.ggpht.com/_N5aAiuG68RA/Sk_kW7wuEBI/AAAAAAAAAYk/iWyBB-T1UFk/image_thumb13.png?imgmax=800" width="515" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;As you can see, this shows the tag, the number of times it occurs in the system and the total number of posts in the system. We can then return this data through the TagCount object (which has just three properties: Count, Tag and TotalPosts) from our Data Layer function GetTagCloud: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="wlWriterEditableSmartContent" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:6898a19b-1712-4db6-ae10-5e0b13eb47ce" style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px; padding-top: 5px"&gt;&lt;br /&gt;&lt;div style="border: #000080 1px solid; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt;&lt;br /&gt;&lt;div style="background-color: #ffffff; max-height: 300px; overflow: scroll; padding: 2px 5px; white-space: nowrap"&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;br /&gt; &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#2b91af"&gt;IList&lt;/span&gt;&amp;lt;SubForum.DataAccess.Objects.&lt;span style="color:#2b91af"&gt;TagCount&lt;/span&gt;&amp;gt; GetTagCloud()&lt;br&gt;&lt;br /&gt;        {&lt;br&gt;&lt;br /&gt;            System.Data.&lt;span style="color:#2b91af"&gt;IDbCommand&lt;/span&gt; command = &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;;&lt;br&gt;&lt;br /&gt;            &lt;span style="color:#2b91af"&gt;IDataReader&lt;/span&gt; dataReader = &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;;&lt;br&gt;&lt;br /&gt;            &lt;span style="color:#2b91af"&gt;List&lt;/span&gt;&amp;lt;SubForum.DataAccess.Objects.&lt;span style="color:#2b91af"&gt;TagCount&lt;/span&gt;&amp;gt; returnList = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;List&lt;/span&gt;&amp;lt;SubForum.DataAccess.Objects.&lt;span style="color:#2b91af"&gt;TagCount&lt;/span&gt;&amp;gt;();&lt;br&gt;&lt;br /&gt;            &lt;span style="color:#2b91af"&gt;IDbConnection&lt;/span&gt; connection = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; System.Data.SqlClient.&lt;span style="color:#2b91af"&gt;SqlConnection&lt;/span&gt;(&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.ConnectionString);&lt;br&gt;&lt;br /&gt;            &lt;span style="color:#0000ff"&gt;try&lt;/span&gt;&lt;br&gt;&lt;br /&gt;            {&lt;br&gt;&lt;br /&gt;                connection.Open();&lt;br&gt;&lt;br /&gt;                command = connection.CreateCommand();&lt;br&gt;&lt;br /&gt;                command.CommandText = &lt;span style="color:#a31515"&gt;"Select Count(1) As Count, PostTags.Tag As Tag, (select count(*) from Posts) as To"&lt;/span&gt; +&lt;br&gt;&lt;br /&gt;                    &lt;span style="color:#a31515"&gt;"talPosts&amp;#92;nFrom PostTags&amp;#92;nGroup By PostTags.Tag&amp;#92;nOrder By &amp;#92;'Count&amp;#92;' Desc"&lt;/span&gt;;&lt;br&gt;&lt;br /&gt;                System.&lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;"Executing Query: {0}"&lt;/span&gt;, command.CommandText);&lt;br&gt;&lt;br /&gt;                dataReader = command.ExecuteReader();&lt;br&gt;&lt;br /&gt;                &lt;span style="color:#0000ff"&gt;for&lt;/span&gt; (&lt;br&gt;&lt;br /&gt;                ; dataReader.Read(); &lt;br&gt;&lt;br /&gt;                )&lt;br&gt;&lt;br /&gt;                {&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;                    SubForum.DataAccess.Objects.&lt;span style="color:#2b91af"&gt;TagCount&lt;/span&gt; modelObj = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; SubForum.DataAccess.Objects.&lt;span style="color:#2b91af"&gt;TagCount&lt;/span&gt;();&lt;br&gt;&lt;br /&gt;                    modelObj.Tag = ((&lt;span style="color:#2b91af"&gt;String&lt;/span&gt;)(dataReader[&lt;span style="color:#a31515"&gt;"Tag"&lt;/span&gt;]));&lt;br&gt;&lt;br /&gt;                    &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; ((dataReader[&lt;span style="color:#a31515"&gt;"Count"&lt;/span&gt;].Equals(&lt;span style="color:#2b91af"&gt;DBNull&lt;/span&gt;.Value) == &lt;span style="color:#0000ff"&gt;false&lt;/span&gt;))&lt;br&gt;&lt;br /&gt;                    {&lt;br&gt;&lt;br /&gt;                        modelObj.Count = ((&lt;span style="color:#0000ff"&gt;int&lt;/span&gt;)(dataReader[&lt;span style="color:#a31515"&gt;"Count"&lt;/span&gt;]));&lt;br&gt;&lt;br /&gt;                    }&lt;br&gt;&lt;br /&gt;                    &lt;span style="color:#0000ff"&gt;else&lt;/span&gt;&lt;br&gt;&lt;br /&gt;                    {&lt;br&gt;&lt;br /&gt;                        modelObj.Count = &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;;&lt;br&gt;&lt;br /&gt;                    }&lt;br&gt;&lt;br /&gt;                    &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; ((dataReader[&lt;span style="color:#a31515"&gt;"TotalPosts"&lt;/span&gt;].Equals(&lt;span style="color:#2b91af"&gt;DBNull&lt;/span&gt;.Value) == &lt;span style="color:#0000ff"&gt;false&lt;/span&gt;))&lt;br&gt;&lt;br /&gt;                    {&lt;br&gt;&lt;br /&gt;                        modelObj.TotalPosts = ((&lt;span style="color:#0000ff"&gt;int&lt;/span&gt;)(dataReader[&lt;span style="color:#a31515"&gt;"TotalPosts"&lt;/span&gt;]));&lt;br&gt;&lt;br /&gt;                    }&lt;br&gt;&lt;br /&gt;                    &lt;span style="color:#0000ff"&gt;else&lt;/span&gt;&lt;br&gt;&lt;br /&gt;                    {&lt;br&gt;&lt;br /&gt;                        modelObj.TotalPosts = &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;;&lt;br&gt;&lt;br /&gt;                    }&lt;br&gt;&lt;br /&gt;                    returnList.Add(modelObj);&lt;br&gt;&lt;br /&gt;                }&lt;br&gt;&lt;br /&gt;            }&lt;br&gt;&lt;br /&gt;            &lt;span style="color:#0000ff"&gt;finally&lt;/span&gt;&lt;br&gt;&lt;br /&gt;            {&lt;br&gt;&lt;br /&gt;                &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; ((dataReader != &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;))&lt;br&gt;&lt;br /&gt;                {&lt;br&gt;&lt;br /&gt;                    ((System.&lt;span style="color:#2b91af"&gt;IDisposable&lt;/span&gt;)(dataReader)).Dispose();&lt;br&gt;&lt;br /&gt;                }&lt;br&gt;&lt;br /&gt;                &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; ((command != &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;))&lt;br&gt;&lt;br /&gt;                {&lt;br&gt;&lt;br /&gt;                    ((System.&lt;span style="color:#2b91af"&gt;IDisposable&lt;/span&gt;)(command)).Dispose();&lt;br&gt;&lt;br /&gt;                }&lt;br&gt;&lt;br /&gt;                &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; ((connection != &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;))&lt;br&gt;&lt;br /&gt;                {&lt;br&gt;&lt;br /&gt;                    connection.Close();&lt;br&gt;&lt;br /&gt;                    ((System.&lt;span style="color:#2b91af"&gt;IDisposable&lt;/span&gt;)(connection)).Dispose();&lt;br&gt;&lt;br /&gt;                }&lt;br&gt;&lt;br /&gt;            }&lt;br&gt;&lt;br /&gt;            &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; returnList;&lt;br&gt;&lt;br /&gt;        \&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&amp;#160; The ForumController that handles all the Forum MVC requests has a GetTagCloud() function that returns the model for the View:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="wlWriterEditableSmartContent" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:42023000-a0d8-44c0-b1cc-193c28f7fc6f" style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px; padding-top: 5px"&gt;&lt;br /&gt;&lt;div style="border: #000080 1px solid; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt;&lt;br /&gt;&lt;div style="background-color: #ffffff; max-height: 300px; overflow: scroll; padding: 2px 5px; white-space: nowrap"&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;br /&gt; &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#2b91af"&gt;ActionResult&lt;/span&gt; TagCloud()&lt;br&gt;&lt;br /&gt;        {&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;            &lt;span style="color:#2b91af"&gt;IList&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;TagCount&lt;/span&gt;&amp;gt; tagCountList = DataAccessService.GetTagCloud();&lt;br&gt;&lt;br /&gt; &lt;br&gt;&lt;br /&gt;            &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; View(tagCountList);&lt;br&gt;&lt;br /&gt;        \&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Then comes the user control or the MVC Partial View that displays the tags as links with the right Tag class to use. TagCloud.ascx: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="wlWriterEditableSmartContent" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:2087668f-4336-4b97-a772-b0595bd29048" style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px; padding-top: 5px"&gt;&lt;br /&gt;&lt;div style="border: #000080 1px solid; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt;&lt;br /&gt;&lt;div style="background-color: #ffffff; max-height: 300px; overflow: scroll; padding: 2px 5px; white-space: nowrap"&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="background:#ffee62"&gt;&amp;lt;%&lt;/span&gt;&lt;span style="color:#0000ff"&gt;@&lt;/span&gt; &lt;span style="color:#a31515"&gt;Control&lt;/span&gt; &lt;span style="color:#ff0000"&gt;Language&lt;/span&gt;&lt;span style="color:#0000ff"&gt;="C#"&lt;/span&gt;  &lt;span style="color:#ff0000"&gt;Inherits&lt;/span&gt;&lt;span style="color:#0000ff"&gt;="System.Web.Mvc.ViewUserControl&amp;lt;IList&amp;lt;SubForum.DataAccess.Objects.TagCount&amp;gt;&amp;gt;"&lt;/span&gt; &lt;span style="background:#ffee62"&gt;%&amp;gt;&lt;br&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;h5&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;Tags&lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;h5&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;br&gt;&lt;br /&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;ul&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;br&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="background:#ffee62"&gt;&amp;lt;%&lt;/span&gt;&lt;span&gt; &lt;br&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; totalNumberOfTags = &lt;span style="color:#0000ff"&gt;base&lt;/span&gt;.Model.Count;&lt;br&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;&lt;span style="color:#0000ff"&gt;foreach&lt;/span&gt; (SubForum.DataAccess.Objects.&lt;span style="color:#2b91af"&gt;TagCount&lt;/span&gt; tagCount &lt;span style="color:#0000ff"&gt;in&lt;/span&gt; &lt;span style="color:#0000ff"&gt;base&lt;/span&gt;.Model)&lt;br&gt;&lt;br /&gt;{&lt;br&gt;&lt;br /&gt;    &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (!&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;.IsNullOrEmpty(tagCount.Tag))&lt;br&gt;&lt;br /&gt;    {&lt;br&gt;&lt;br /&gt;        &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; tagClass = SubForum.Web.Controllers.&lt;span style="color:#2b91af"&gt;ForumController&lt;/span&gt;.GetTagClass(tagCount.Count.Value, tagCount.TotalPosts.Value);&lt;br&gt;&lt;br /&gt;&lt;span style="background:#ffee62"&gt;%&amp;gt;&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;li&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background:#ffee62"&gt;&amp;lt;%&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&lt;/span&gt;Html.RouteLink(&lt;br&gt;&lt;br /&gt;                tagCount.Tag,&lt;br&gt;&lt;br /&gt;                &lt;span style="color:#a31515"&gt;"Tag"&lt;/span&gt;,&lt;br&gt;&lt;br /&gt;                &lt;span style="color:#0000ff"&gt;new&lt;/span&gt;&lt;br&gt;&lt;br /&gt;                {&lt;br&gt;&lt;br /&gt;                    controller = &lt;span style="color:#a31515"&gt;"Forum"&lt;/span&gt;,&lt;br&gt;&lt;br /&gt;                    action = &lt;span style="color:#a31515"&gt;"Tag"&lt;/span&gt;,&lt;br&gt;&lt;br /&gt;                    id = tagCount.Tag&lt;br&gt;&lt;br /&gt;                },&lt;br&gt;&lt;br /&gt;                      &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; { id = tagClass }&lt;br&gt;&lt;br /&gt;          )&lt;span style="background:#ffee62"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;li&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;&lt;br /&gt;  &lt;span style="background:#ffee62"&gt;&amp;lt;%&lt;/span&gt;&lt;span&gt;}&lt;br&gt;&lt;br /&gt;}&lt;/span&gt;&lt;span style="background:#ffee62"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;ul&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;br&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The UI calls the GetTagClass() function to determine which TagClass from the CSS to use:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="wlWriterEditableSmartContent" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:1fd5a669-cc73-4bbc-aa85-850d284b3ef3" style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px; padding-top: 5px"&gt;&lt;br /&gt;&lt;div style="border: #000080 1px solid; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt;&lt;br /&gt;&lt;div style="background-color: #ffffff; max-height: 300px; overflow: scroll; padding: 2px 5px; white-space: nowrap"&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;br /&gt;  &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; GetTagClass(&lt;span style="color:#0000ff"&gt;int&lt;/span&gt; category, &lt;span style="color:#0000ff"&gt;int&lt;/span&gt; articles)&lt;br&gt;&lt;br /&gt;        {&lt;br&gt;&lt;br /&gt;            &lt;span style="color:#0000ff"&gt;var&lt;/span&gt; result = (category * 100) / articles;&lt;br&gt;&lt;br /&gt;            &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (result &amp;lt;= 1)&lt;br&gt;&lt;br /&gt;                &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#a31515"&gt;"tag1"&lt;/span&gt;;&lt;br&gt;&lt;br /&gt;            &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (result &amp;lt;= 4)&lt;br&gt;&lt;br /&gt;                &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#a31515"&gt;"tag2"&lt;/span&gt;;&lt;br&gt;&lt;br /&gt;            &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (result &amp;lt;= 8)&lt;br&gt;&lt;br /&gt;                &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#a31515"&gt;"tag3"&lt;/span&gt;;&lt;br&gt;&lt;br /&gt;            &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (result &amp;lt;= 12)&lt;br&gt;&lt;br /&gt;                &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#a31515"&gt;"tag4"&lt;/span&gt;;&lt;br&gt;&lt;br /&gt;            &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (result &amp;lt;= 18)&lt;br&gt;&lt;br /&gt;                &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#a31515"&gt;"tag5"&lt;/span&gt;;&lt;br&gt;&lt;br /&gt;            &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (result &amp;lt;= 30)&lt;br&gt;&lt;br /&gt;                &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#a31515"&gt;"tag5"&lt;/span&gt;;&lt;br&gt;&lt;br /&gt;            &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; result &amp;lt;= 50 ? &lt;span style="color:#a31515"&gt;"tag6"&lt;/span&gt; : &lt;span style="color:#a31515"&gt;""&lt;/span&gt;;&lt;br&gt;&lt;br /&gt;        }&lt;br&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;These Tag classes match our CSS that has the following definition: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="wlWriterEditableSmartContent" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:abd0d998-d360-4611-863c-3b65c6387d64" style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px; padding-top: 5px"&gt;&lt;br /&gt;&lt;div style="border: #000080 1px solid; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt;&lt;br /&gt;&lt;div style="background-color: #ffffff; max-height: 300px; overflow: scroll; padding: 2px 5px; white-space: nowrap"&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt; &lt;span style="color:#a31515"&gt;.tag1&lt;/span&gt;{&lt;span style="color:#ff0000"&gt;font-size&lt;/span&gt;: &lt;span style="color:#0000ff"&gt;0.8&lt;/span&gt; &lt;span style="color:#0000ff"&gt;em&lt;/span&gt;}&lt;br&gt;&lt;br /&gt;&lt;span style="color:#a31515"&gt;.tag2&lt;/span&gt;{&lt;span style="color:#ff0000"&gt;font-size&lt;/span&gt;: &lt;span style="color:#0000ff"&gt;0.9em&lt;/span&gt;}&lt;br&gt;&lt;br /&gt;&lt;span style="color:#a31515"&gt;.tag3&lt;/span&gt;{&lt;span style="color:#ff0000"&gt;font-size&lt;/span&gt;: &lt;span style="color:#0000ff"&gt;1em&lt;/span&gt;}&lt;br&gt;&lt;br /&gt;&lt;span style="color:#a31515"&gt;.tag4&lt;/span&gt;{&lt;span style="color:#ff0000"&gt;font-size&lt;/span&gt;: &lt;span style="color:#0000ff"&gt;1.2em&lt;/span&gt;}&lt;br&gt;&lt;br /&gt;&lt;span style="color:#a31515"&gt;.tag5&lt;/span&gt;{&lt;span style="color:#ff0000"&gt;font-size&lt;/span&gt;: &lt;span style="color:#0000ff"&gt;1.4em&lt;/span&gt;}&lt;br&gt;&lt;br /&gt;&lt;span style="color:#a31515"&gt;.tag6&lt;/span&gt;{&lt;span style="color:#ff0000"&gt;font-size&lt;/span&gt;: &lt;span style="color:#0000ff"&gt;1.7em&lt;/span&gt;}&lt;br&gt;&lt;br /&gt;&lt;span style="color:#a31515"&gt;.tag7&lt;/span&gt;{&lt;span style="color:#ff0000"&gt;font-size&lt;/span&gt;: &lt;span style="color:#0000ff"&gt;2.0em&lt;/span&gt;}&lt;br&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Finally, in our Master page we will call the controller to Render the Partial View TagCloud.ascx and shows us all the tags in the system appropriately weighted:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="wlWriterEditableSmartContent" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:66b0b834-dd9a-44fd-b9c6-d52d257c3164" style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px; padding-top: 5px"&gt;&lt;br /&gt;&lt;div style="border: #000080 1px solid; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt;&lt;br /&gt;&lt;div style="background-color: #ffffff; max-height: 300px; overflow: scroll; padding: 2px 5px; white-space: nowrap"&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;div&lt;/span&gt; &lt;span style="color:#ff0000"&gt;id&lt;/span&gt;&lt;span style="color:#0000ff"&gt;="tags"&amp;gt;&lt;/span&gt;&lt;br&gt;&lt;br /&gt;    &lt;span style="background:#ffee62"&gt;&amp;lt;%&lt;/span&gt;&lt;span&gt; Html.RenderAction&amp;lt;SubForum.Web.Controllers.&lt;/span&gt;&lt;span style="color:#2b91af"&gt;ForumController&lt;/span&gt;&amp;gt;(c =&amp;gt; c.TagCloud());&lt;span style="background:#ffee62"&gt;%&amp;gt;&lt;br&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;div&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;This yields a plain and simple TagCloud looking as such, with the most popular showing first :&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://lh3.ggpht.com/_N5aAiuG68RA/Sk_kXKK3ALI/AAAAAAAAAYo/rQR-uKB7TUs/s1600-h/image28.png"&gt;&lt;img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="78" alt="image" src="http://lh6.ggpht.com/_N5aAiuG68RA/Sk_kXW_V_dI/AAAAAAAAAYs/AD8pzU1vvkg/image_thumb16.png?imgmax=800" width="644" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Extension&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The Tag Cloud can be extended by limiting the Tags to a predefined set of tags instead of making it free for all. That can simply be done by adding a Tags table which holds all the system’s predefined Tags and only allowing users to pick from those tags. The overall working of this code and the SQL would not be affected at all.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;You can also return the top 10 or however many tags that you want to be displayed instead of displaying all the tags by simply adding a Top clause to your query:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;a style="color: #0000ff" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;amp;siteid=us%2Fdev&amp;amp;p=1&amp;amp;nq=NEW&amp;amp;qu=Select&amp;amp;IntlSearch=&amp;amp;boolean=PHRASE&amp;amp;ig=01&amp;amp;i=09&amp;amp;i=99"&gt;Select&lt;/a&gt; &lt;a style="color: #0000ff" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;amp;siteid=us%2Fdev&amp;amp;p=1&amp;amp;nq=NEW&amp;amp;qu=Top&amp;amp;IntlSearch=&amp;amp;boolean=PHRASE&amp;amp;ig=01&amp;amp;i=09&amp;amp;i=99"&gt;Top&lt;/a&gt; 10 &lt;a style="color: #0000ff" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;amp;siteid=us%2Fdev&amp;amp;p=1&amp;amp;nq=NEW&amp;amp;qu=Count&amp;amp;IntlSearch=&amp;amp;boolean=PHRASE&amp;amp;ig=01&amp;amp;i=09&amp;amp;i=99"&gt;Count&lt;/a&gt;(1) &lt;a style="color: #0000ff" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;amp;siteid=us%2Fdev&amp;amp;p=1&amp;amp;nq=NEW&amp;amp;qu=As&amp;amp;IntlSearch=&amp;amp;boolean=PHRASE&amp;amp;ig=01&amp;amp;i=09&amp;amp;i=99"&gt;As&lt;/a&gt; &lt;a style="color: #0000ff" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;amp;siteid=us%2Fdev&amp;amp;p=1&amp;amp;nq=NEW&amp;amp;qu=Count&amp;amp;IntlSearch=&amp;amp;boolean=PHRASE&amp;amp;ig=01&amp;amp;i=09&amp;amp;i=99"&gt;Count&lt;/a&gt;, PostTags.Tag &lt;a style="color: #0000ff" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;amp;siteid=us%2Fdev&amp;amp;p=1&amp;amp;nq=NEW&amp;amp;qu=As&amp;amp;IntlSearch=&amp;amp;boolean=PHRASE&amp;amp;ig=01&amp;amp;i=09&amp;amp;i=99"&gt;As&lt;/a&gt; Tag, (&lt;a style="color: #0000ff" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;amp;siteid=us%2Fdev&amp;amp;p=1&amp;amp;nq=NEW&amp;amp;qu=Select&amp;amp;IntlSearch=&amp;amp;boolean=PHRASE&amp;amp;ig=01&amp;amp;i=09&amp;amp;i=99"&gt;Select&lt;/a&gt; &lt;a style="color: #0000ff" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;amp;siteid=us%2Fdev&amp;amp;p=1&amp;amp;nq=NEW&amp;amp;qu=Count&amp;amp;IntlSearch=&amp;amp;boolean=PHRASE&amp;amp;ig=01&amp;amp;i=09&amp;amp;i=99"&gt;Count&lt;/a&gt;(*)&lt;br /&gt;  &lt;a style="color: #0000ff" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;amp;siteid=us%2Fdev&amp;amp;p=1&amp;amp;nq=NEW&amp;amp;qu=From&amp;amp;IntlSearch=&amp;amp;boolean=PHRASE&amp;amp;ig=01&amp;amp;i=09&amp;amp;i=99"&gt;From&lt;/a&gt; Posts) &lt;a style="color: #0000ff" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;amp;siteid=us%2Fdev&amp;amp;p=1&amp;amp;nq=NEW&amp;amp;qu=As&amp;amp;IntlSearch=&amp;amp;boolean=PHRASE&amp;amp;ig=01&amp;amp;i=09&amp;amp;i=99"&gt;As&lt;/a&gt; TotalPosts&lt;br /&gt;&lt;a style="color: #0000ff" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;amp;siteid=us%2Fdev&amp;amp;p=1&amp;amp;nq=NEW&amp;amp;qu=From&amp;amp;IntlSearch=&amp;amp;boolean=PHRASE&amp;amp;ig=01&amp;amp;i=09&amp;amp;i=99"&gt;From&lt;/a&gt; PostTags&lt;br /&gt;&lt;a style="color: #0000ff" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;amp;siteid=us%2Fdev&amp;amp;p=1&amp;amp;nq=NEW&amp;amp;qu=Group&amp;amp;IntlSearch=&amp;amp;boolean=PHRASE&amp;amp;ig=01&amp;amp;i=09&amp;amp;i=99"&gt;Group&lt;/a&gt; &lt;a style="color: #0000ff" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;amp;siteid=us%2Fdev&amp;amp;p=1&amp;amp;nq=NEW&amp;amp;qu=By&amp;amp;IntlSearch=&amp;amp;boolean=PHRASE&amp;amp;ig=01&amp;amp;i=09&amp;amp;i=99"&gt;By&lt;/a&gt; PostTags.Tag&lt;br /&gt;&lt;a style="color: #0000ff" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;amp;siteid=us%2Fdev&amp;amp;p=1&amp;amp;nq=NEW&amp;amp;qu=Order&amp;amp;IntlSearch=&amp;amp;boolean=PHRASE&amp;amp;ig=01&amp;amp;i=09&amp;amp;i=99"&gt;Order&lt;/a&gt; &lt;a style="color: #0000ff" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;amp;siteid=us%2Fdev&amp;amp;p=1&amp;amp;nq=NEW&amp;amp;qu=By&amp;amp;IntlSearch=&amp;amp;boolean=PHRASE&amp;amp;ig=01&amp;amp;i=09&amp;amp;i=99"&gt;By&lt;/a&gt; '&lt;span style="color: #8b0000"&gt;Count&lt;/span&gt;' &lt;a style="color: #0000ff" href="http://search.microsoft.com/default.asp?so=RECCNT&amp;amp;siteid=us%2Fdev&amp;amp;p=1&amp;amp;nq=NEW&amp;amp;qu=Desc&amp;amp;IntlSearch=&amp;amp;boolean=PHRASE&amp;amp;ig=01&amp;amp;i=09&amp;amp;i=99"&gt;Desc&lt;/a&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;With this approach all the code from the UI layer including the CSS down to the Data Layer is shown. The approach is universal to any database engine or provider you may want to use and there is nothing hidden except the workings of the MVC Framework. You can see a live demo (if it is up :) ) at &lt;a href="http://www.PortaltoolBox.net"&gt;www.PortaltoolBox.net&lt;/a&gt; or checkout the actual source on &lt;a href="http://www.subforum.net"&gt;www.subforum.net&lt;/a&gt;.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/134352470375907644-6689647747430940458?l=www.adnanahmad.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.adnanahmad.net/feeds/6689647747430940458/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.adnanahmad.net/2009/07/simple-tag-cloud-implementation-for.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/134352470375907644/posts/default/6689647747430940458'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/134352470375907644/posts/default/6689647747430940458'/><link rel='alternate' type='text/html' href='http://www.adnanahmad.net/2009/07/simple-tag-cloud-implementation-for.html' title='Simple Tag Cloud Implementation for ASP.NET MVC'/><author><name>Adnan Ahmad</name><uri>http://www.blogger.com/profile/01008287176974220401</uri><email>blog@adnanahmad.net</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='13175912509193909219'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-134352470375907644.post-5722772983226131220</id><published>2009-06-22T20:11:00.001-07:00</published><updated>2009-06-22T21:22:16.983-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='orm'/><category scheme='http://www.blogger.com/atom/ns#' term='data access pattern'/><title type='text'>The Only Pattern for Data Access is - There Are No Patterns for Data Access</title><content type='html'>&lt;p&gt;Over the years of software development, one thing that has eluded most developers is Data Access. Yes, I mean writing code that accesses a database from your application. It is an age old problem since the days when data storage and computing were invented.&lt;/p&gt;  &lt;p&gt;We would have thought that by now we would have been able to come up with a clean universal pattern for data access such as the M-V-C pattern for User Interfaces or the Singleton pattern or the Factory pattern. Yet, today we find ourselves with a plethora of technologies and patterns that are constantly struggling to survive to the next release. Just ask yourself, how many iterations of the ORM paradigm have come and gone?&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;J2EE with EJBs and Hibernate must be the answer!&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;In the JAVA world the creation of EJBs, Hibernate and its adoption into the J2EE spec surely would have put an end to the Data Access Layer misery developers faced. But it soon got notorious for being overly complicated, bloated and expensive to develop and maintain. Developers found that it was easy to run queries or stored procedures straight against their databases and get their data directly. Many of them did so in shame and said to themselves, this is hack but ORM way is really the true way. It became obvious when they ran their applications that that their apps ran better, faster and were easier to read without using the full EJB functionality.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;The notoriously heavy datasets&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;At one time it seemed like Microsoft with their DataSets had won over the Database access world by providing simple disconnected objects that were easily bound to UI’s and were able to do queries to the database or even in memory when they were loaded. But alas they became notoriously heavy, hard to maintain and transport and had to be revamped. Microsoft has dabbed with many iterations of Data Access Layers including Object Spaces, Active Recordsets, LINQ to SQL and Entity Framework. Some of these are still in the market trying to survive like LINQ to SQL, some have become part of history like Active Recordsets and some never made it into sight like Object Spaces and some claim to take over the future like Entity Framework! &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Why do none of the Data Access Layer Patterns work?&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;In my opinion after having used and worked on many projects that use the above mentioned technologies, &lt;em&gt;the only pattern I see is a pattern of failure&lt;/em&gt;. The reason is that these technologies try to mimic the database. They make it look like the user is abstracted from the database by doing what a database does instead of abstracting what a database should do. They completely miss the concept of abstraction. When I abstract something in my code, the job of that abstraction is to hide the internal complexity of something, not repeat the actual work of what I am abstracting. &lt;/p&gt;  &lt;p&gt;Failed data access layers abstract the database by repeating the work of databases. That is the number one rule of failure. How so you maybe asking. You may say, I love writing my LINQ queries and not having to worry about SQL. The problem begins right there. ORM data access implementations have to implement their own query language! If you have to implement your own query language you are venturing into the complex world of set theory and relational tuples. You better be as good and as fast as a database engine on that or else you will soon be history.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;The Pattern of Redundancy instead of Abstraction&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Caching database data in memory is another database copy-cat feature. You better provide better caching, latency, and redundancy algorithms than the database or you are going to face the wrath of the Database Engine pretty soon! I doubt any Data Access technology can beat the caching of query execution plans and caching recently used data provided by the leading database engines such as the commercial engines like Oracle and SQL Server or even the free ones like MySql. Database caches work better even over the network in the long term than the most powerful Object caching providers I have worked with. &lt;/p&gt;  &lt;p&gt;These features of database access patterns or technologies do not do justice to the database engines they try to tame and therefore soon get bypassed and blown away to their competitor: the no data access layer pattern.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;What is the no data access layer pattern?&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;The no data access layer pattern is simple; access or persist your data through the native database provider, using the native query language of database engine (SQL). If you stick to this pattern you will be more successful than not in your applications! The only rule of abstraction that you should follow is use data access to populate only application objects that need to be populated or persisted from your application and you should be good. Nothing more nothing less!&lt;/p&gt;  &lt;p&gt;Let’s take an oath to ourselves and say, &lt;strong&gt;“&lt;em&gt;Thou shall not be fooled by another Data Access Pattern or technology!”.&lt;/em&gt;&lt;/strong&gt; It is like looking for the Abominable snowman. If there was any truth to it we would have found it by now.&lt;/p&gt;  &lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2ftheahmadblog.blogspot.com%2f2009%2f06%2fonly-pattern-for-data-access-is-there.html"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2ftheahmadblog.blogspot.com%2f2009%2f06%2fonly-pattern-for-data-access-is-there.html" border="0" alt="kick it on DotNetKicks.com" /&gt;&lt;/a&gt; | &lt;a rel="nofollow" href="http://www.dotnetshoutout.com/submit?url=http%3a%2f%2ftheahmadblog.blogspot.com%2f2009%2f06%2fonly-pattern-for-data-access-is-there.html"&gt;                 Shout it!&lt;/a&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/134352470375907644-5722772983226131220?l=www.adnanahmad.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.adnanahmad.net/feeds/5722772983226131220/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.adnanahmad.net/2009/06/only-pattern-for-data-access-is-there.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/134352470375907644/posts/default/5722772983226131220'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/134352470375907644/posts/default/5722772983226131220'/><link rel='alternate' type='text/html' href='http://www.adnanahmad.net/2009/06/only-pattern-for-data-access-is-there.html' title='The Only Pattern for Data Access is - There Are No Patterns for Data Access'/><author><name>Adnan Ahmad</name><uri>http://www.blogger.com/profile/01008287176974220401</uri><email>blog@adnanahmad.net</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='13175912509193909219'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-134352470375907644.post-2598671225287819966</id><published>2009-06-17T05:08:00.001-07:00</published><updated>2009-06-17T05:14:34.633-07:00</updated><title type='text'>Regional Conflicts</title><content type='html'>&lt;p&gt;We have all come to love our IDE features and take them for granted nowadays. Features like intellisense, code-complete, refactoring and code organization and of course the use of Regions.&lt;/p&gt;  &lt;p&gt;The #region and #endregion keywords basically provide the ability to hide code and collapse it into a short word or phrase provided at the beginning of the block with the IDE showing a plus sign to expand and collapse the region.&lt;/p&gt;  &lt;p&gt;Eg: #region Public Methods&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; #endregion&lt;/p&gt;  &lt;p&gt;While regions are handy and have become popular, I use them myself occasionally. I don’t particularly fancy them, neither do they improve my code’s readability by much. I believe in keeping my code concise, using descriptive names for methods, classes, variables, etc. and keeping my classes short and easy to read. But sometimes a region for collapsing those using statements and grouping similar methods like constructors, private variables and properties, disposing, etc comes handy.&lt;/p&gt;  &lt;p&gt;As regions help you “hide” your code some developers like to abuse it to hide shameful code. &lt;/p&gt;  &lt;p&gt;Let me share with you an example I saw recently. Here the developer is mapping data from his objects to an external system based on keys. The code for this method went of for a few hundred lines of code having a mapping for every field the external system needed.&lt;/p&gt;  &lt;pre&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; GetMapDataValue(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; key, Account accountObject) &lt;br /&gt;        {&lt;br /&gt;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;switch&lt;/span&gt; (key) &lt;br /&gt;            { &lt;br /&gt;                #region Account Data&lt;br /&gt;&lt;br /&gt;                &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; &amp;quot;&lt;span style="color: #8b0000"&gt;AccountFirstName&lt;/span&gt;&amp;quot;: &lt;br /&gt;                &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; &amp;quot;&lt;span style="color: #8b0000"&gt;FirstName&lt;/span&gt;&amp;quot;: &lt;br /&gt;                    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; accountObject.FirstName;&lt;br /&gt;&lt;br /&gt;                &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; &amp;quot;&lt;span style="color: #8b0000"&gt;AccountLastName&lt;/span&gt;&amp;quot;: &lt;br /&gt;                    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; accountObject.LastName;&lt;br /&gt;&lt;br /&gt;                #endregion&lt;br /&gt;&lt;br /&gt;                #region Address Data&lt;br /&gt;&lt;br /&gt;                &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; &amp;quot;&lt;span style="color: #8b0000"&gt;AddressLine1&lt;/span&gt;&amp;quot;: &lt;br /&gt;                    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; accountObject.PrimaryAddress.Line1;&lt;br /&gt;&lt;br /&gt;                &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; &amp;quot;&lt;span style="color: #8b0000"&gt;AddressLine2&lt;/span&gt;&amp;quot;: &lt;br /&gt;                    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; accountObject.PrimaryAddress.Line2;&lt;br /&gt;&lt;br /&gt;                &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; &amp;quot;&lt;span style="color: #8b0000"&gt;AddressCity&lt;/span&gt;&amp;quot;: &lt;br /&gt;                    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; accountObject.PrimaryAddress.City;&lt;br /&gt;&lt;br /&gt;                &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; &amp;quot;&lt;span style="color: #8b0000"&gt;AddressState&lt;/span&gt;&amp;quot;: &lt;br /&gt;                    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; accountObject.PrimaryAddress.State;&lt;br /&gt;&lt;br /&gt;                &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; &amp;quot;&lt;span style="color: #8b0000"&gt;AddressZip&lt;/span&gt;&amp;quot;: &lt;br /&gt;                    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; accountObject.PrimaryAddress.Zip;&lt;br /&gt;&lt;br /&gt;                #endregion&lt;br /&gt;&lt;br /&gt;                ……&lt;br /&gt;&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;        }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;After collapsing the regions, the code looks like this:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://lh4.ggpht.com/_N5aAiuG68RA/SjjcuK4PeBI/AAAAAAAAAXo/owPuA1sieLg/s1600-h/image5.png"&gt;&lt;img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="243" alt="image" src="http://lh5.ggpht.com/_N5aAiuG68RA/Sjjcuk-uoSI/AAAAAAAAAXs/G5lObU_9u5I/image_thumb2.png?imgmax=800" width="623" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;This clearly shows that the developer is trying to write separate methods for mapping different pieces of data but instead choose to shove all the code in a switch case statement broken up into different regions for each specific piece of information. It may look organized but in reality it’s a poorly designed function that has been “regionized” to look readable. A classic case of hiding your dirty laundry in the closet.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Another strange use of regions I have seen over the years since regions have been around is the use of regions as grouping methods as if they were writing classes. This is a classic example from my procedural programmer friends who really have not gotten on the Object Oriented boat that left the shore a long time ago!&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Here is an example:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; DataAccess&lt;br /&gt;    {&lt;br /&gt;        #region Account Data&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; InsertAccount(Account account)&lt;br /&gt;        {&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; DeleteAccount(&lt;span style="color: #0000ff"&gt;long&lt;/span&gt;  accountId)&lt;br /&gt;        {&lt;br /&gt;            ...&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; UpdateAccount(Account account)&lt;br /&gt;        {&lt;br /&gt;            ...&lt;br /&gt;        }&lt;br /&gt;        &lt;br /&gt;        #endregion&lt;br /&gt;&lt;br /&gt;        #region Order Data&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; InsertOrder(Order order)&lt;br /&gt;        {&lt;br /&gt;            ...&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; DeleteOrder(&lt;span style="color: #0000ff"&gt;long&lt;/span&gt;  orderId)&lt;br /&gt;        {&lt;br /&gt;            ...&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; UpdateOrder(Order order)&lt;br /&gt;        {&lt;br /&gt;            ...&lt;br /&gt;        }&lt;br /&gt;        &lt;br /&gt;        #endregion&lt;br /&gt;&lt;br /&gt;        ... you &lt;span style="color: #0000ff"&gt;get&lt;/span&gt; the point ...&lt;br /&gt;    }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;A class like this went on for the few hundred objects in the system that needed to be persisted and was no less than 10,000 lines of code! The developer boasted the code to his colleagues and marveled at it. I remember working on this code file. It was so big that even the intellisense started to choke up. When I typed ‘this’ and hit the period key it caused the machine to run on overdrive for a few seconds before the list showed up! Now that is some serious regioning!&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;I don't want to give directions on how to use regions but I will say that if you design your code well and make sure your program functionality is broken down in to understandable, re-usable and maintainable classes you will find that your code does not need to be regionalized much. Short concise classes broken down into short descriptive methods will take you far in keeping your code organized and readable. By default the IDE makes methods, classes, and namespaces into regions and that should be enough for the majority of the code you will write!&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/134352470375907644-2598671225287819966?l=www.adnanahmad.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.adnanahmad.net/feeds/2598671225287819966/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.adnanahmad.net/2009/06/regional-conflicts_17.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/134352470375907644/posts/default/2598671225287819966'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/134352470375907644/posts/default/2598671225287819966'/><link rel='alternate' type='text/html' href='http://www.adnanahmad.net/2009/06/regional-conflicts_17.html' title='Regional Conflicts'/><author><name>Adnan Ahmad</name><uri>http://www.blogger.com/profile/01008287176974220401</uri><email>blog@adnanahmad.net</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='13175912509193909219'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-134352470375907644.post-5131733046620048082</id><published>2009-06-05T18:02:00.000-07:00</published><updated>2009-06-14T13:40:40.172-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='use'/><category scheme='http://www.blogger.com/atom/ns#' term='linq'/><category scheme='http://www.blogger.com/atom/ns#' term='c#'/><category scheme='http://www.blogger.com/atom/ns#' term='var'/><category scheme='http://www.blogger.com/atom/ns#' term='abuse'/><title type='text'>Var Wars – Abuse of the CSharp var</title><content type='html'>&lt;p&gt; &lt;/p&gt;  &lt;p&gt;CSharp 3.0 introduced the var keyword for declaring variables without having to explicitly specify the type. This was done for using anonymous types returned from LINQ queries. Now, I am seeing many developers use it all over their code and think its a good thing. &lt;/p&gt;  &lt;p&gt;Wasn’t C# developed to enforce strongly typed programming? &lt;/p&gt;  &lt;p&gt;Var just makes it harder to infer the type when reading and maintaining code. &lt;/p&gt;  &lt;p&gt;Take for example this LINQ Query:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;var user = from u &lt;span class="kwrd"&gt;in&lt;/span&gt; Users &lt;span class="kwrd"&gt;where&lt;/span&gt; user.Status == UserStatus.Active&lt;br /&gt;          select u;&lt;/pre&gt;It is hard enough to infer the type from the above query, let alone infer the type from a statement like this:&lt;br /&gt;&lt;pre class="csharpcode"&gt;var index = 1; (Is index an &lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;long&lt;/span&gt;?)&lt;/pre&gt;Just because a compiler can infer the type does not mean a human should have to be forced to do it when reading it. If we wrote code just to make compilers happy we should be writing Assembly. Why then use an Object Oriented Language? But since code is written for developers to be able to read and maintain it and not just for compilers to compile it, it should be as descriptive and readable as possible.&lt;br /&gt;&lt;p&gt;Some say it cuts down on repetitive code when used in a statement like this:  &lt;/p&gt;&lt;pre class="csharpcode"&gt;var user = &lt;span class="kwrd"&gt;new&lt;/span&gt; User();&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;For those who are so obsessed with cutting down characters and lines of code, here is a small piece of advice that will better save you coding time and characters: focus on better design and architecture. If you are so concerned about repetitive code – your energy will be well rewarded. Well designed code is always shorter, cleaner, easier to read and also works better! &lt;/p&gt;&lt;p&gt;Cutting down on type names is like removing the wrapper from a drink. You have to infer what is in it by drinking it. For those who don’t care about their calories go ahead, but for the rest us, please put the wrappers! &lt;/p&gt;The only time you really have to use var is for anonymous types. There is no other way to get an anonymous type. For everything else a type name can and should be used for variable declaration.&lt;br /&gt;&lt;p&gt;So for those var abusers, spare the rest of us some inferring and just declare your variables with a type name.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/134352470375907644-5131733046620048082?l=www.adnanahmad.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.adnanahmad.net/feeds/5131733046620048082/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.adnanahmad.net/2009/06/var-wars-abuse-of-c-30-var.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/134352470375907644/posts/default/5131733046620048082'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/134352470375907644/posts/default/5131733046620048082'/><link rel='alternate' type='text/html' href='http://www.adnanahmad.net/2009/06/var-wars-abuse-of-c-30-var.html' title='Var Wars – Abuse of the CSharp var'/><author><name>Adnan Ahmad</name><uri>http://www.blogger.com/profile/01008287176974220401</uri><email>blog@adnanahmad.net</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='13175912509193909219'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-134352470375907644.post-2138154397779392911</id><published>2009-06-04T04:54:00.001-07:00</published><updated>2009-06-05T18:16:18.942-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='introduction'/><category scheme='http://www.blogger.com/atom/ns#' term='blog'/><category scheme='http://www.blogger.com/atom/ns#' term='adnan ahmad'/><category scheme='http://www.blogger.com/atom/ns#' term='welcome'/><title type='text'>Welcome</title><content type='html'>&lt;p&gt;Welcome to my blog. You may have read some of my postings at &lt;a href="http://www.orasissoftware.com/blog"&gt;www.orasissoftware.com/blog&lt;/a&gt; or &lt;a href="http://stackoverflow.com/users/45518/ahmad"&gt;StackOverflow.com&lt;/a&gt; talking about data access technologies, ORMs and code generation. I will continue to blog from now on on this site. I also will guest blog on &lt;a href="http://www.wijix.com/"&gt;http://www.wijix.com/&lt;/a&gt; whose site and concept I really like; it has many useful, well written utilities and code snippets for programmer’s use.&lt;/p&gt;&lt;p&gt;Although I don’t want limit myself to blogging on any particular topic, I will promise one thing that you will find on this blog. Everything will be original, informative, unique in perspective and always with a critical eye. I like to raise the bar when it comes to software development. No company or technology is too big or too good to be criticized and challenged! So subscribe now and be part of the conversation!&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/134352470375907644-2138154397779392911?l=www.adnanahmad.net' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.adnanahmad.net/feeds/2138154397779392911/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.adnanahmad.net/2009/06/welcome.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/134352470375907644/posts/default/2138154397779392911'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/134352470375907644/posts/default/2138154397779392911'/><link rel='alternate' type='text/html' href='http://www.adnanahmad.net/2009/06/welcome.html' title='Welcome'/><author><name>Adnan Ahmad</name><uri>http://www.blogger.com/profile/01008287176974220401</uri><email>blog@adnanahmad.net</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='13175912509193909219'/></author><thr:total>0</thr:total></entry></feed>