<?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:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-834688215084300455</id><updated>2012-01-27T10:04:34.794-08:00</updated><category term='SharePoint'/><category term='Crystal Reports'/><category term='AJAX'/><category term='LINQ'/><category term='MVC'/><category term='Architecture'/><category term='General'/><category term='WCF'/><category term='Software Architecture'/><category term='Database'/><category term='Tech-Ed MEA'/><category term='ASP.NET'/><title type='text'>.NET &amp; Architecture Thoughts</title><subtitle type='html'>An insight into .NET Framework and Software Architecture</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://dotnetpost.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://dotnetpost.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Kashif Ahmad</name><uri>http://www.blogger.com/profile/02151423871584093787</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>42</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-834688215084300455.post-1142766148734762707</id><published>2011-05-31T12:08:00.000-07:00</published><updated>2011-05-31T12:11:00.485-07:00</updated><title type='text'>Information System</title><content type='html'>In this blog entry, I will talk about what are Information Systems? what are the different types of Information Systems and what benefits do they provide? More to follow shortly. Stay tuned for more...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/834688215084300455-1142766148734762707?l=dotnetpost.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetpost.blogspot.com/feeds/1142766148734762707/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetpost.blogspot.com/2011/05/information-system.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/1142766148734762707'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/1142766148734762707'/><link rel='alternate' type='text/html' href='http://dotnetpost.blogspot.com/2011/05/information-system.html' title='Information System'/><author><name>Kashif Ahmad</name><uri>http://www.blogger.com/profile/02151423871584093787</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-834688215084300455.post-397153648029461373</id><published>2011-03-13T09:54:00.000-07:00</published><updated>2011-03-13T10:17:22.509-07:00</updated><title type='text'>SQL Server EXCEPT Clause</title><content type='html'>&lt;span style="font-family:Verdana;"&gt;A few days back I had performance issues with a query in SQL Server 2005. The query was a nested query similar to the following (details omitted for brevity):&lt;br /&gt;&lt;br /&gt;SELECT&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;EmployeeID, DateAttended&lt;br /&gt;FROM&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;CourseDetails&lt;br /&gt;WHERE&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;EmployeeID NOT IN&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;(&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SELECT &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;EmployeeID &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FROM&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CourseDetails&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;WHERE&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;isActive = 0&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;)&lt;br /&gt;&lt;br /&gt;The above query would return all data rows where [Courses] are 'Active'. Due to the slow query, the web application was timing out. After doing some research, I finally came across the wonder &lt;b&gt;EXCEPT&lt;/b&gt; clause in SQL Server 2005. &lt;br /&gt;&lt;br /&gt;The EXCEPT clause returns all rows from the first query which are not present in the second query. It's more like a LEFT JOIN where rows from the left tables are returned. It is important to note that both the first and second query must have same data columns with similar data types.&lt;br /&gt;&lt;br /&gt;Using the &lt;b&gt;EXCEPT&lt;/b&gt; clause, we can now rewrite the above query as following:&lt;br /&gt;&lt;br /&gt;SELECT&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;EmployeeID, DateAttended&lt;br /&gt;FROM&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;CourseDetails&lt;br /&gt;EXCEPT&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;SELECT &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;EmployeeID &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;FROM&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CourseDetails&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;WHERE&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;isActive = 0&lt;br /&gt;&lt;br /&gt;To my joy, the performance of the query was lightening fast. It really worked like a charm. So my advice would be to use the EXCEPT clause wherever possible and avoid nested queries.&lt;br /&gt;&lt;br /&gt;I hope you found this blog use. Stay tuned for more.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/834688215084300455-397153648029461373?l=dotnetpost.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetpost.blogspot.com/feeds/397153648029461373/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetpost.blogspot.com/2011/03/sql-server-except-clause.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/397153648029461373'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/397153648029461373'/><link rel='alternate' type='text/html' href='http://dotnetpost.blogspot.com/2011/03/sql-server-except-clause.html' title='SQL Server EXCEPT Clause'/><author><name>Kashif Ahmad</name><uri>http://www.blogger.com/profile/02151423871584093787</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-834688215084300455.post-3429713140186220209</id><published>2011-02-28T11:54:00.001-08:00</published><updated>2011-03-01T09:53:48.100-08:00</updated><title type='text'>Using Surrogate Key in Databases</title><content type='html'>&lt;span style="font-family:Verdana;"&gt;I prefer using surrogate key (a non business key used as an identifier e.g. Instead of using a StudentID as an identifier, we may use a separate RowID column to identify each student record) whenever I can. Different people have different opinions about using surrogate keys in databases. Some will always use a surrogate key while others won’t. It all comes down to the personal preference of a database developer.&lt;br /&gt;&lt;br /&gt;However, based on my experience working with surrogate keys, I am off the opinion that surrogate keys are both good and bad. Don’t get me wrong when I call them bad. They don’t do any harm rather add to the working load on behalf of the developer. Following are some of the pros and cons of using a surrogate key: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;PROS&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;1. Primary keys (or natural keys) are hard to change. In programming, there are times when we may need to change the primary key e.g. we can change a Student-ID from type char (6) to char (8) to accommodate more students. If Student-ID is defined as a primary key, it must have links in several tables. This means, the change must be reflected in all the associated tables (a nightmare for a developer). However, if a separate surrogate key is defined, Student-ID type can be changed without affecting multiple tables.&lt;br /&gt;&lt;br /&gt;2. A surrogate key can assist developers in programming e.g. suppose a table has a surrogate key defined while the unique key is defined by the combination of three columns. If the data in this table is displayed in a gridview in asp.net, the developer can easily write code to Update and Delete records based on the primary key. In this case, he doesn’t have to worry about all three keys which define the unique key.&lt;br /&gt;&lt;br /&gt;3. There is no locking contention since a surrogate key is generated by the database and cached making them highly scalable. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;CONS&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;1. Data integrity becomes the responsibility of the developer. Whenever a record is inserted or updated, the developer must check if a similar natural key already exists to avoid duplication. If the natural key was defined as the primary key, the database would take care of data integrity.&lt;br /&gt;&lt;br /&gt;2. Excessive joins are needed since joins are dependent on keys with business value and not a surrogate key e.g. to get details of a student from different tables, a developer would prefer to use his Registration-ID and not a surrogate key.&lt;br /&gt; &lt;br /&gt;3. An separate index must be defined on the natural key.&lt;br /&gt;&lt;br /&gt;4. From a programming point of view, surrogate keys cannot be used as a search key.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I hope you find this blog as useful. Stay tuned for more...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/834688215084300455-3429713140186220209?l=dotnetpost.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetpost.blogspot.com/feeds/3429713140186220209/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetpost.blogspot.com/2011/02/using-surrogate-key-in-databases.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/3429713140186220209'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/3429713140186220209'/><link rel='alternate' type='text/html' href='http://dotnetpost.blogspot.com/2011/02/using-surrogate-key-in-databases.html' title='Using Surrogate Key in Databases'/><author><name>Kashif Ahmad</name><uri>http://www.blogger.com/profile/02151423871584093787</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-834688215084300455.post-3238023055537495904</id><published>2011-02-28T08:54:00.000-08:00</published><updated>2011-03-01T09:54:20.559-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='General'/><title type='text'>I start writing again - finally!</title><content type='html'>&lt;span style="font-family:Verdana;"&gt;I have been away from blogging for quite some time. This can be attributed to my busy schedule (and some what laziness :-). However, I now plan to write on regular basis. I have some interesting topics in mind to start with. I also plan to finish my incomplete &lt;b&gt;'LINQ Explained'&lt;/b&gt; series. Honestly, LINQ is one topic which requires thorough and deep understanding of concepts before talking about it. In coming days, I also plan to blog about &lt;b&gt;SharePoint Server, Enterprise Concepts and ASP.NET&lt;/b&gt;. So stay tuned for more...&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/834688215084300455-3238023055537495904?l=dotnetpost.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetpost.blogspot.com/feeds/3238023055537495904/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetpost.blogspot.com/2011/02/i-start-writing-again-finally.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/3238023055537495904'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/3238023055537495904'/><link rel='alternate' type='text/html' href='http://dotnetpost.blogspot.com/2011/02/i-start-writing-again-finally.html' title='I start writing again - finally!'/><author><name>Kashif Ahmad</name><uri>http://www.blogger.com/profile/02151423871584093787</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-834688215084300455.post-1200399606443508797</id><published>2010-06-19T11:36:00.000-07:00</published><updated>2010-06-21T06:29:41.269-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Database'/><title type='text'>Creating SQL Server Limited User Account</title><content type='html'>&lt;span style="font-family:Verdana;"&gt;Sometimes you need to create a limited user account in SQL Server 2005. This is a trivial task but I find many new DB developers struggling to do so. However, if you understand the underlying concept, it indeed is trivial. &lt;br /&gt;&lt;br /&gt;This is how I find new DB developers creating a limited user account:&lt;br /&gt;&lt;br /&gt;1. Open up SQL Server Management Studio&lt;br /&gt;2. Expand the desired DB &gt; Security&lt;br /&gt;3. Right click on Users and select New User…&lt;br /&gt;4. In the Database User – New dialog, enter in a User name following by a Login name. Usually both are the same&lt;br /&gt;5. &lt;b&gt;Bang&lt;/b&gt;. This is where you get the  error “&lt;b&gt;Error 15007 when trying to add a new user&lt;/b&gt;”&lt;br /&gt;&lt;br /&gt;So what went wrong in the above steps? The answer is that you cannot create a &lt;b&gt;User Role&lt;/b&gt; without first creating a &lt;b&gt;Login&lt;/b&gt;. A Login connects to an SQL Server instance while a User Role defines the database access level. In other words:&lt;br /&gt;&lt;br /&gt;Login – SQL Server Level&lt;br /&gt;User – Database Level&lt;br /&gt;&lt;br /&gt;Now to create a limited user account, you following steps have to be followed:&lt;br /&gt;&lt;br /&gt;1. Open up SQL Server Management Studio&lt;br /&gt;2. Expand &lt;b&gt;Security&lt;/b&gt;. You will see a &lt;b&gt;Logins&lt;/b&gt; node. Right click on Logins and click on &lt;b&gt; New Login…&lt;/b&gt;&lt;br /&gt;3. In the Login – New dialog, enter in a &lt;b&gt;Login name&lt;/b&gt;&lt;br /&gt;4. Next click on &lt;b&gt;SQL Server Authentication&lt;/b&gt; radio button. Enter and confirm &lt;b&gt;Password&lt;/b&gt;.&lt;br /&gt;5. From &lt;b&gt;Default database&lt;/b&gt;, select the desired database. Now you are done creating a &lt;b&gt;Login&lt;/b&gt;. The next step is to create his specific role&lt;br /&gt;6. Under the SQL Server instance node, Expand &lt;b&gt;Databases &gt; [Database] &gt; Security&lt;/b&gt;. You will see a &lt;b&gt;Users&lt;/b&gt; node.&lt;br /&gt;7. Right click on &lt;b&gt;Users&lt;/b&gt; and select &lt;b&gt;New User…&lt;/b&gt;&lt;br /&gt;8. In the Database User – New dialog, under &lt;b&gt;General page&lt;/b&gt;, enter in &lt;b&gt;User name&lt;/b&gt;&lt;br /&gt;9. In front of &lt;b&gt;Login name&lt;/b&gt;, click on the browse (…) button. You will see a &lt;b&gt;Select Login&lt;/b&gt; dialog&lt;br /&gt;10. Click on &lt;b&gt;Browse&lt;/b&gt; button and check the &lt;b&gt;Login&lt;/b&gt; you created above and click OK. Close the &lt;b&gt;Select Login&lt;/b&gt; dialog by click on OK&lt;br /&gt;11. Next under &lt;b&gt;Database User – New&lt;/b&gt; dialog, click on &lt;b&gt;Securables&lt;/b&gt; page. Click on &lt;b&gt;Add&lt;/b&gt; button. This will open up &lt;b&gt;Add Objects&lt;/b&gt; dialog.&lt;br /&gt;12. Select &lt;b&gt;Specific objects&lt;/b&gt; and click OK. This will open up &lt;b&gt;Select Objects&lt;/b&gt; dialog. &lt;br /&gt;13. Click on &lt;b&gt;Object Types&lt;/b&gt; button. This will open up &lt;b&gt;Select Object Types&lt;/b&gt; dialog.&lt;br /&gt;14. Check the desired object type (Tables, Views, Stored Procedures etc) which &lt;b&gt;Login&lt;/b&gt; will have access to. Click OK&lt;br /&gt;15. Under &lt;b&gt;Select Objects&lt;/b&gt; dialog, click on &lt;b&gt;Browse&lt;/b&gt; button. This will open up &lt;b&gt;Browse for Objects&lt;/b&gt; dialog. Select the desired objects which &lt;b&gt;Login&lt;/b&gt; will have access to. Click OK.&lt;br /&gt;16. Click on OK to close &lt;b&gt;Select Objects&lt;/b&gt; dialog.&lt;br /&gt;17. Under &lt;b&gt;Database User - New&lt;/b&gt;, you can select each object in &lt;b&gt;Securables&lt;/b&gt; list and specify permission level on each object in the &lt;b&gt;Explicit permissions for&lt;/b&gt; list&lt;br /&gt;18. Click on OK to close the &lt;b&gt;Database User - New&lt;/b&gt; dialog. You have now set permissions on the specific user.&lt;br /&gt;&lt;br /&gt;I hope you have found this post to be useful. Please do provide your feedback and stay tuned for more…&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/834688215084300455-1200399606443508797?l=dotnetpost.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetpost.blogspot.com/feeds/1200399606443508797/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetpost.blogspot.com/2010/06/creating-sql-server-limited-user.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/1200399606443508797'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/1200399606443508797'/><link rel='alternate' type='text/html' href='http://dotnetpost.blogspot.com/2010/06/creating-sql-server-limited-user.html' title='Creating SQL Server Limited User Account'/><author><name>Kashif Ahmad</name><uri>http://www.blogger.com/profile/02151423871584093787</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-834688215084300455.post-7011726384091144500</id><published>2010-06-19T11:35:00.000-07:00</published><updated>2010-06-19T11:37:40.701-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='General'/><title type='text'>Understanding HTML, XHTML and DHTML</title><content type='html'>&lt;span style="font-family:Verdana;"&gt;As programmers, we come across the terms HTML, XHTML and DHTML on a daily basis. The difference between these is subtle but important to understand. This post will elaborate these concepts in further details. I would suggest reading my other post &lt;a href=””&gt;HTML Document Structure&lt;/a&gt; before proceeding. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;HTML&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;&lt;i&gt;Hyper Text Markup Language or HTML&lt;/i&gt; is a markup language used for creating web documents. It has the following characteristics:&lt;br /&gt;&lt;br /&gt;1. HTML is a markup language and not a programming language.&lt;br /&gt;2. HTML is an application of SGML (Standard Generalized Markup Language). SGML is a system for defining markup languages. &lt;br /&gt;3. HTML markup consists of elements where each element has a start and end tag. The content of the element is contained between the two tags.&lt;br /&gt;4. HTML also includes character reference and symbols such as ‘&amp;amp;lt;’ is used to represent the ‘&amp;lt;’ sign.&lt;br /&gt;5. An HTML document allows comments.&lt;br /&gt;6. HTML documents are validated by Document Type Definition or DTD. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;XHTML&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;&lt;i&gt;Extensible Hyper Text Markup Language or XHTML&lt;/i&gt; is the reevaluation of HTML 4. Both have sharp resembles but with subtle differences. However, the most critical difference between the two is that &lt;i&gt;XHTML is an application of XML &lt;/i&gt;. This means that XHTML follows the XML syntax rules for validating web documents. These rules include the following:&lt;br /&gt;&lt;br /&gt;1. XHTML is case-sensitive.&lt;br /&gt;2. The entire document has only one root element.&lt;br /&gt;3. Elements must be nested in the correct order.&lt;br /&gt;4. Every element must have a closing tag leading to a well-formed document. Elements without content such ‘br’ must have a self-closing tag.&lt;br /&gt;5. The element tags and attributes are in lowercase.&lt;br /&gt;6. Attributes must be in double or single quotes.&lt;br /&gt;7. Each attribute must have a corresponding value. There is no notion of default values.&lt;br /&gt;8. If there is a syntax error in the XHTML document, the entire document is aborted from loading.&lt;br /&gt;9. Comments are limited in XHTML.&lt;br /&gt;10. The &lt;i&gt;id&lt;/i&gt; attribute is used instead of &lt;i&gt;name&lt;/i&gt; attribute.&lt;br /&gt;&lt;br /&gt;Since XHTML complies with the above rules, it is portable across different platforms including web browsers, mobile phones, palm devices or any reduced browser. HTML, on the other hand, can ignore these rules altogether leading to document with syntax errors.&lt;br /&gt;&lt;br /&gt;XHTML also deals with CSS differently. This includes the following characteristics:&lt;br /&gt;&lt;br /&gt;1. &lt;i&gt;Element Selectors&lt;/i&gt; are case sensitive.&lt;br /&gt;2. In HTML certain properties (background, overflow) of the BODY element applies to the root HTML element as well. This is not true for XHTML.&lt;br /&gt;3. In HTML, even if we omit some tags, elements still exist in the DOM and hence the CSS properties apply to them. This is not true for XHTML. The CSS will only apply to elements with proper markup.&lt;br /&gt;4. MIME types (&lt;i&gt;Content-Type&lt;/i&gt; header specified in HTML/XHTML document) are very important when using style-sheets in XHTML document. An XHTML document can work with application/xhtml+xml, application/xml and text/xml MIME types. An XHMTL document using text/xml MIME type is parsed as HTML. However, a style sheet written specifically for XHTML document may not work with text/xml MIME type (since its interpreted as HTML).&lt;br /&gt;&lt;br /&gt;XHTML also deals with JavaScript differently. Some of these characteristics include the following:&lt;br /&gt;&lt;br /&gt;1. XHTML does not support the .innerHTML property.&lt;br /&gt;2. XHTML does not support document.write () otherwise it confuses the browser which is unable to tell whether a document is well formed or not. For example suppose we have a tag &amp;lt;/MyTag&amp;gt; somewhere in the document. Obviously this is not a well formed tag. However, if somewhere above JavaScript uses the statement ‘document.write (“&amp;lt;MyTag&amp;gt;”);’ it will make it a valid tag. This means that unless the document is fully served, the browser cannot if it is a well formed document.&lt;br /&gt;3. DOM methods are replaced by respective namespace-based methods. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;DHTML&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;Unlike HTML and XHTML, &lt;i&gt;Dynamic HTML or DHTML&lt;/i&gt; is not an industry standard and is not supported by W3C, IEEE or ISO. The term DHTM was coined by Microsoft. DHTML represents a set of several technologies/standards including HTML/XHTML, DOM, CSS and JavaScript. The merger of these technologies leads to development of Rich Client Applications. HTML/XHTML and CSS are used to create the static but rich visual appearance while JavaScript and DOM are used to make the web applications dynamic.&lt;br /&gt;&lt;br /&gt;With this we come to the end of this post. I hope this post has given you a good idea about the difference between HTML, XHTML and DHTML. Do provide your feedback and stay tuned for more…&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/834688215084300455-7011726384091144500?l=dotnetpost.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetpost.blogspot.com/feeds/7011726384091144500/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetpost.blogspot.com/2010/06/understanding-html-xhtml-and-dhtml.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/7011726384091144500'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/7011726384091144500'/><link rel='alternate' type='text/html' href='http://dotnetpost.blogspot.com/2010/06/understanding-html-xhtml-and-dhtml.html' title='Understanding HTML, XHTML and DHTML'/><author><name>Kashif Ahmad</name><uri>http://www.blogger.com/profile/02151423871584093787</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-834688215084300455.post-7781262805304122019</id><published>2010-06-17T12:42:00.001-07:00</published><updated>2010-06-17T12:53:34.891-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='General'/><title type='text'>HTML Document Structure</title><content type='html'>&lt;span style="font-family:Verdana;"&gt; In this post, I will talk about HTML Document Structure. This post is not a tutorial on HTML for which you can find many useful links online. This post will give you an overview of what a typical HTML Document looks like. So let us dive in straight. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;What is HTML&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;&lt;i&gt;Hyper Text Markup Language or HTML&lt;/i&gt; is a markup language (and not a programming language) used for creating web pages. One may ask what a markup language is. Well a markup language uses tags to create different parts of a document. To better understand this, you must notice when a person reviews a document and &lt;b&gt;&lt;i&gt;marks (underline, highlight)&lt;/b&gt;&lt;/i&gt; any spelling, grammatical or technical mistakes. At the end of the review, the document will probably have several markups. The same concept applies to a markup language where different tags create the contents of a webpage.&lt;br /&gt;&lt;br /&gt;A HTML document contains different parts known as elements. For example, to make some text bold, we use the &amp;lt;b&amp;gt;&amp;lt;/b&amp;gt; element. Each element can be divided into three parts; &lt;i&gt;&lt;b&gt;Start Tag, Content and End Tag&lt;/b&gt;&lt;/i&gt;. A tag is a ‘markup’ which is delimited by &amp;lt; and &amp;gt;. The End tag has an additional ‘/’ after &amp;lt;. In the above example, the start tag is &amp;lt;b&amp;gt; and the end tag is &amp;lt;/b&amp;gt;. The contents of the element are surrounded by the start and end tags. Some elements (such as new-line break &amp;lt;/br&amp;gt;) do not need a closing tag as they have no Content.&lt;br /&gt;&lt;br /&gt;Each element can also have attributes. An attribute represents a property of the element. For example, an &lt;i&gt;input&lt;/i&gt; element has a &lt;i&gt;type&lt;/i&gt; attribute where the type may specify it as button or text box. Attribute values must be delimited in single or double quotes. Attributes are only included in the start tag and are case-insensitive. However, their values can be case-sensitive.&lt;br /&gt;&lt;br /&gt;The following listing shows what a typical HTML document looks like:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Listing 1&lt;/b&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;&amp;lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&amp;gt;&lt;br/&gt;&lt;br /&gt;&amp;lt;html xmlns="http://www.w3.org/1999/xhtml" &amp;gt; &lt;br/&gt;&lt;br /&gt;&amp;lt;head&amp;gt; &lt;br/&gt;&lt;br /&gt;    &amp;lt;title&amp;gt;Untitled Page&amp;lt;/title&amp;gt; &lt;br/&gt;&lt;br /&gt;&amp;lt;/head&amp;gt; &lt;br/&gt;&lt;br /&gt;&amp;lt;body&amp;gt; &lt;br/&gt;&lt;br /&gt;        &amp;lt;h1&amp;gt;HTML Document&amp;lt;/h1&amp;gt; &lt;br/&gt;&lt;br /&gt;        &amp;lt;p&amp;gt;This post talks about a HTML Document&amp;lt;/p&amp;gt; &lt;br/&gt;&lt;br /&gt;&amp;lt;/body&amp;gt; &lt;br/&gt;&lt;br /&gt;&amp;lt;/html&amp;gt; &lt;br/&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;Now let us explore the above document in greater detail. &lt;/span&gt;&lt;br/&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;!DOCTYPE Declaration&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt; Each HTML Document begins with &lt;i&gt;Document Type Declaration or DOCTYPE&lt;/i&gt;. This is a standard defined under HTML rules. The !DOCTYPE defines the version of HTML used by the HTML document. This information is used by web browsers to validate the document’s syntax. &lt;br /&gt;&lt;br /&gt;The DOCTYPE instructs the browser to associate a particular &lt;i&gt;Document Type Definition or DTD&lt;/i&gt; - which defines set of rules for a markup language – with an HTML document. Typically, a browser consists of a &lt;i&gt;layout engine&lt;/i&gt; which performs “switching” to switch over to the particular DTD defined in the DOCTYPE definition. This way, the browser knows precisely which DTD Rules to apply to render the HTML Web Page correctly. Following are the different DOCTYPE definitions supported by HTML 4.01:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;HTML 4.01 Strict :&lt;/b&gt; This DTD includes standard HTML elements and attributes but does not include presentational elements such as fonts. This DTD does not allow Framesets. The definition takes the following form:&lt;br /&gt;&amp;lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt; HTML 4.01 Transitional :&lt;/b&gt; This DTD includes standard HTML elements and attributes in addition to presentation elements including fonts. Frameset is not allowed. The definition takes the following form:&lt;br /&gt;&amp;lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt; HTML 4.01 Frameset :&lt;/b&gt; This DTD is the same as HTML 4.01 Transitional in addition to Frameset support. The definition takes the following form:&lt;br /&gt;&amp;lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd"&amp;gt;&lt;br /&gt;&lt;br /&gt;The above are the standard DTD types supported by HTML 4.01. With the release of XTHML (&lt;b&gt;HTML which conforms to XML standards&lt;/b&gt; - more on this in my following post), the following additional DTD types have been introduced:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;XHTML 1.0 Strict&lt;/b&gt;: Similar to its HTML 4.01 Strict counterpart with support for XHTML. The definition is of the following form:&lt;br /&gt;&amp;lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&amp;gt; &lt;br /&gt;&lt;br /&gt;&lt;b&gt;XHTML 1.0 Transitional :&lt;/b&gt; Similar to its HTML 4.01 Transitional counterpart with support for XHTML. The definition takes the following form:&lt;br /&gt;&amp;lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;XHTML 1.0 Frameset :&lt;/b&gt; Again similar to its HTML 4.01 Frameset counterpart with support for XHTML. The definition takes the following form:&lt;br /&gt;&amp;lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;XHTML 1.1:&lt;/b&gt; Similar to its XHTML 1.0 Strict in addition to allowing adding modules. The definition takes the following form:&lt;br /&gt;&amp;lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"&amp;gt; &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;HTML Element&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt; The HTML element is the root element and acts as the parent container for the rest of the elements. The rest of the elements are contained within the start and end tag or the HTML element as shown in Listing 1. The two child elements of the HTML element are discussed in the following paragraphs. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;HEAD Element&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt; The HEAD element holds set of different tags which provide page related information. This section is the first part to be loaded in the browser. The HEAD section contains the following elements:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Title :&lt;/b&gt; Provides a brief description of the webpage such as ‘HTML Tutorial’ or ‘Welcome to my homepage’&lt;br /&gt;&lt;b&gt;STYLE :&lt;/b&gt; This element defines the stylesheet for a webpage. A stylesheet defines the visual layout of a webpage including colors, margins, background etc.&lt;br /&gt;&lt;b&gt;META :&lt;/b&gt; META element allows defining information about the document. It is like information about information. It does not describe the contents of he webpage. For example, this information can include the author of the page, page language, date-created etc. This information is in the form of name/value pairs and is also used by Search Engines while indexing the webpage. &lt;br /&gt;&lt;b&gt;SCRIPT :&lt;/b&gt;This element allows defining scripts such as JavaScript, VB Script for the webpage.&lt;br /&gt;&lt;br /&gt;Amongst the above, only the TITLE element is a visual. The rest are non-visual elements used for information keeping. As mentioned above, the HEAD sections loads first in the browser that’s why you can see the title even before the page is rendered. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;BODY Element&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt; The BODY element defines the contents of a webpage. The contents of the webpage may include headings, tables, paragraphs, images, hyperlinks etc. The body may be implemented using the BODY or the FRAMESET element. Framesets are used to divide the webpage into different portions. &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/834688215084300455-7781262805304122019?l=dotnetpost.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetpost.blogspot.com/feeds/7781262805304122019/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetpost.blogspot.com/2010/06/html-document-structure.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/7781262805304122019'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/7781262805304122019'/><link rel='alternate' type='text/html' href='http://dotnetpost.blogspot.com/2010/06/html-document-structure.html' title='HTML Document Structure'/><author><name>Kashif Ahmad</name><uri>http://www.blogger.com/profile/02151423871584093787</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-834688215084300455.post-180774501069878227</id><published>2010-03-19T10:04:00.000-07:00</published><updated>2010-05-10T09:41:12.984-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Database'/><title type='text'>Avoiding Cursors in SQL Server 2005</title><content type='html'>&lt;br&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;In this post, I will show you a technique which replicates a cursor in SQL Server. The idea is to avoid the overhead of using cursors in SQL Server. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Problem with using Cursors&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt; Some time ago, I used cursors in one of my stored procedure. This procedure returned data which was consumed by a reporting screen. I was working with a limited amount of data for testing purpose so the screen worked great (at least for a while). But when the same stored procedure ran on the production machine with tables having hundreds of thousands of rows, the screen just went slow like anything. The stored procedure returned the data in almost 10 minutes (only). This was acceptable to me :) but not to my management LOL.&lt;br /&gt;&lt;br /&gt;I started to debug the stored procedure and it finally dawned on me that the cursors in the stored procedure were causing the application to choke. After doing some &lt;span style="text-decoration: line-through;"&gt;googling&lt;/span&gt; binging, it was clear to me that that cursors have a performance overhead.&lt;br /&gt;&lt;br /&gt;Cursors in SQL Server are great when we need to process data on a row by row basis. Usually a query returns a static dataset, However; at times, we need to process the data for each row before it is returned. This is where cursors come in handy. However cursors can have a performance issue if not used properly. I will not go into details of describing problems associated with cursors. You can find many useful articles online on this subject.&lt;br /&gt;&lt;br /&gt;So the hundred thousand million dollar question is that how we can we avoid cursors but still get the same functionality. The point is to be able to process each row before we can return the data. Well there are many techniques to replicate a cursor. In the following section, I will show you the use of Temporary Table to implement cursor functionality. &lt;/span&gt;&lt;br /&gt; &lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Using Temporary Table to avoid Cursors&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt; A Temporary Table is used to store data temporarily. When using a temporary table, the table and its data is stored on the disk in the &lt;i&gt;tempdb&lt;/i&gt; database. A temporary table can be local or global. A local temporary table is only visible to user who created it and only within the connection which created it. Local variables get dropped when the connection is closed. The basic syntax of creating a Temporary Table is as follows: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;CREATE TABLE #MyTable&lt;br /&gt;(&lt;br /&gt; ID  int,&lt;br /&gt; Address varchar (50)&lt;br /&gt;)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt; On the other hand, a global temporary table is visible to anyone connected to the SQL Server instance. These tables are dropped when the last connection to the table is closed. The syntax for creating temporary table is as follows: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;CREATE TABLE ##MyTable&lt;br /&gt;(&lt;br /&gt; ID  int,&lt;br /&gt; Address varchar (50)&lt;br /&gt;)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt; To replicate cursors, I will use temporary table in the following code. &lt;br /&gt;&lt;br /&gt;&lt;b&gt;Code Listing&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;USE Northwind&lt;br /&gt;&lt;br /&gt;-- Ref 1 - Create temporary table&lt;br /&gt;CREATE TABLE #EmployeeData &lt;br /&gt;(&lt;br /&gt; employeeID  INT UNIQUE CLUSTERED,   &lt;br /&gt; lastName  VARCHAR (20),  &lt;br /&gt; firstName  VARCHAR (20),  &lt;br /&gt; isProcessed  BIT&lt;br /&gt;)&lt;br /&gt;&lt;br /&gt;-- Ref 2 - Insert Data in temporary table&lt;br /&gt;INSERT INTO &lt;br /&gt; #EmployeeData&lt;br /&gt; SELECT&lt;br /&gt;  EmployeeID, LastName, FirstName, 0&lt;br /&gt; FROM&lt;br /&gt;  Employees&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;DECLARE @employeeID INT&lt;br /&gt;DECLARE @fName  VARCHAR (20)&lt;br /&gt;DECLARE @lName  VARCHAR (20)&lt;br /&gt;&lt;br /&gt;-- Ref 3 - Loop through data in the temporary table&lt;br /&gt;WHILE EXISTS (SELECT employeeID FROM #EmployeeData WHERE isProcessed = 0)&lt;br /&gt;BEGIN&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; -- Ref 4 - Get top employeeID with flag not set&lt;br /&gt; SELECT TOP (1) &lt;br /&gt;  @employeeID = employeeID,&lt;br /&gt;  @lName = lastName,&lt;br /&gt;  @fName = firstName&lt;br /&gt; FROM &lt;br /&gt;  #EmployeeData &lt;br /&gt; WHERE &lt;br /&gt;  isProcessed = 0&lt;br /&gt;&lt;br /&gt; -- Now you can process the data. For bravity, I will only print the full-name&lt;br /&gt; PRINT @fName + ' ' + @lName&lt;br /&gt; &lt;br /&gt; -- Ref 4 - Set flag for the currently selected employeeID&lt;br /&gt; UPDATE #EmployeeData SET isProcessed = 1 WHERE employeeID = @employeeID&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;DROP TABLE #EmployeeData&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt; Let me explain the above reference points one by one:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Ref 1: &lt;/b&gt; Create a temporary table. The fourth column will be used as a flag to traverse each row replicating a cursor&lt;br /&gt;&lt;b&gt;Ref 2: &lt;/b&gt; Insert table from Employee table into temporary table. Set the flag column equal to 0&lt;br /&gt;&lt;b&gt;Ref 3: &lt;/b&gt; Traverse each row in temporary table using the fourth column. Loop through each row until flag is equal to 0&lt;br /&gt;&lt;b&gt;Ref 4: &lt;/b&gt; Update the flag to 1 of the currently selected row. This way the control will move to the next row with flag equal to 0&lt;br /&gt;&lt;br /&gt;I hope the above code is easy to understand now. One question remains that what if we want to traverse the temporary table again. The answer is that all you have to do is update the table by setting the flag equal to 0 using the following regular &lt;i&gt;Update&lt;/i&gt; statement: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;Update &lt;br /&gt;#EmployeeData &lt;br /&gt;Set &lt;br /&gt; isProcessed = 0&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt; Now you are ready to process each row again using the above code. &lt;br /&gt;&lt;br /&gt;I hope that this post has been useful. Please feel free to share your thoughts. And yes, stay tuned for more :)… &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/834688215084300455-180774501069878227?l=dotnetpost.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetpost.blogspot.com/feeds/180774501069878227/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetpost.blogspot.com/2010/03/avoiding-cursors-in-sql-server-2005.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/180774501069878227'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/180774501069878227'/><link rel='alternate' type='text/html' href='http://dotnetpost.blogspot.com/2010/03/avoiding-cursors-in-sql-server-2005.html' title='Avoiding Cursors in SQL Server 2005'/><author><name>Kashif Ahmad</name><uri>http://www.blogger.com/profile/02151423871584093787</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-834688215084300455.post-7689043058754916445</id><published>2010-03-16T00:30:00.000-07:00</published><updated>2010-03-19T12:04:54.620-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Architecture'/><title type='text'>Single Responsibility Principle</title><content type='html'>&lt;br&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt; In this post, I will talk about the &lt;i&gt;Single Responsibility Principle&lt;/i&gt;. Before I dive into this discussion, let us briefly talk about software design.&lt;br /&gt;&lt;br /&gt;Over the years, software complexity has increased exponentially. Diverse business needs are dictating complex software design. Programmers are burdened with learning and writing better code. A programmer either has to write new software or modify an existing code. Writing new software is easy, however; modifying existing code with a bad design is both difficult to understand and refractor. The question is ‘what is a bad software design’ and how do we identify it? Well to answer it, bad design shares the following flaws:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;i&gt;Rigid:&lt;/i&gt;&lt;/b&gt; Changes are hard to make&lt;br /&gt;&lt;b&gt;&lt;i&gt;Fragile:&lt;/i&gt;&lt;/b&gt; Fixing something breaks something else&lt;br /&gt;&lt;b&gt;&lt;i&gt;Immobile:&lt;/i&gt;&lt;/b&gt; Extension to existing code is difficult&lt;br /&gt;&lt;br /&gt;A code is &lt;i&gt;Rigid&lt;/i&gt; when making changes is difficult. Usually you find yourself scratching your head when tasked to change some code written by another programmer. This could be due to two reasons. First, there is no proper flow between classes/modules or second, proper coding standards (such as design patterns) are not followed. Such code is always difficult to understand and more difficult to change. &lt;br /&gt;&lt;br /&gt;A code is &lt;i&gt;Fragile&lt;/i&gt; when making a change breaks something else. How many times has it happened that your boss told you to fix something (which you did proudly) but discovered later that you broke something else? &lt;br /&gt;&lt;br /&gt;Finally a code is &lt;i&gt;Immobile&lt;/i&gt; when it cannot be reused or is difficult to extend. For example, it is always advisable to design a generic Data Access Layer (DAL) which can connect to any database. However, if the DAL is written targeting a specific database and the top management decides to use a different database later on, the programmer ends up cursing himself for writing a general DAL.&lt;br /&gt;&lt;br /&gt;The above design issues can be avoided by adhering to proven best practices in the software industry. This is where design patterns come into play. In this post we will talk about &lt;b&gt;&lt;i&gt;‘Single Responsibility Principle (SRP)’&lt;/i&gt;&lt;/b&gt;. Following posts will also discuss:&lt;br /&gt;&lt;br /&gt;• Open Closed Principle (OCP)&lt;br /&gt;• Liskov Substitution Principle (LSP)&lt;br /&gt;• Dependency Inversion Control (DIC)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Single Responsibility Principle (SRP) &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;&lt;i&gt;Single Responsibility Principle states that ‘a class or module should have only one responsibility’ where a responsibility is a ‘reason for change’&lt;/i&gt;. In plain English this means that a class should serve a single purpose (responsibility). Only the responsibility dictates a change in the class. If a class has more than one responsibility then it will lead to bad design later on. Changes made to a class should not affect others. This principle follows Dijkstra’s ‘Separation of Concern (SOC)’ principle. &lt;br /&gt;&lt;br /&gt;Let me demonstrate this concept with a simple example. Consider the following class: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;public class Employee {&lt;br /&gt;&lt;br /&gt; public EmployeeDTO GetEmployee (int employeeID) &lt;br /&gt;{&lt;br /&gt;  // perform database lookup and get the employee&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public double CalculateSalary (int employeeID)&lt;br /&gt; {&lt;br /&gt;  // perform database lookup and calculate salary&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;The above &lt;i&gt;Employee&lt;/i&gt; class is serving two purposes. First, it returns an employee and second it calculates the salary of the employee. The first function is justified, however; the &lt;i&gt;Employee&lt;/i&gt; class should know anything about calculating the salary of an employee. This means every time the salary calculating formula changes, the &lt;i&gt;Employee&lt;/i&gt; has to be modified. This process should be handled by a separate class. So the above code can be modified as following: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;public class Payroll &lt;br /&gt;{&lt;br /&gt; public double CalculateSalary (int employeeID)&lt;br /&gt; {&lt;br /&gt;  // calculate and return the employee salary&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public class Employee {&lt;br /&gt;&lt;br /&gt; public EmployeeDTO GetEmployee (int employeeID) &lt;br /&gt;{&lt;br /&gt;  // perform database lookup and get the employee&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public double CalculateSalary (int employeeID)&lt;br /&gt; {&lt;br /&gt;  Payroll pay = new Payroll ();&lt;br /&gt;  return pay.CalculateSalary (employeeID);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;I am sure you can spot the change in the above code. The responsibility of calculating the salary is now handled by the &lt;i&gt;Payroll&lt;/i&gt; class. The &lt;i&gt;Employee&lt;/i&gt; class is no longer concerned about how the salary is calculated. It just invokes a method of the &lt;i&gt;Payroll&lt;/i&gt; class and gets the required results. The &lt;i&gt;Payroll&lt;/i&gt; class can be changed without affecting the &lt;i&gt;Employee&lt;/i&gt; class and vice versa.&lt;br /&gt;&lt;br /&gt;One may argue that the &lt;i&gt;Single Responsibility Principle&lt;/i&gt; can result in a plethora of classes. The answer is yes it can. However, having more classes which are simple to manage is better than having a few but complex classes. Managing complex classes is always a burden on the programmer. Simple classes make refracting easy for any future changes. &lt;br /&gt;&lt;br /&gt;I hope this post has been helpful to under the &lt;i&gt;Single Responsibility Principle&lt;/i&gt;. In the following posts, I will discuss some more principles mentioned above. So stay tuned for more. &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/834688215084300455-7689043058754916445?l=dotnetpost.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetpost.blogspot.com/feeds/7689043058754916445/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetpost.blogspot.com/2010/03/single-responsibility-principle.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/7689043058754916445'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/7689043058754916445'/><link rel='alternate' type='text/html' href='http://dotnetpost.blogspot.com/2010/03/single-responsibility-principle.html' title='Single Responsibility Principle'/><author><name>Kashif Ahmad</name><uri>http://www.blogger.com/profile/02151423871584093787</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-834688215084300455.post-5357050392176081137</id><published>2010-03-09T10:05:00.000-08:00</published><updated>2010-03-09T10:11:26.420-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tech-Ed MEA'/><category scheme='http://www.blogger.com/atom/ns#' term='Software Architecture'/><title type='text'>Software Architect</title><content type='html'>&lt;br&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;One of the sessions I attended at Tech-Ed MEA 2010 was on ‘Agile Architect’. This interactive session was steered by &lt;a href=”http://www.hanselman.com/”&gt;Scott Hanselman&lt;/a&gt; and &lt;a href=”http://www.pluralsight.com/community/blogs/aaron/default.aspx”&gt;Aaron Skonnard&lt;/a&gt; who gave valuable insight into the role of a software architect within an organization. So let us jump right into the discussions in the following sections. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Organizational Role&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;A software architect usually reports to the Chief Technology Officer or CTO. The CTO sets the future technology tone for an organization. An architect, on the other hand, articulates the vision of the CTO. He understands the business domain to the heart and conceptualizes the overall business needs into proper software requirements. &lt;br /&gt;&lt;br /&gt;It is important to understand that a software architect is both a technical and political figure in an organization. He understands the business strategies. He understands the business both inside and out including business rules, policies and decisions. In short &lt;i&gt;he must see the big picture&lt;/i&gt; when making his decisions. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Technical Aspect&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;A good software architect must be technology savvy. He understands the technology (to be used) in and out. He is well versed with latest technical trends, programming languages, software methodologies and development tools. This may seem to be an overstatement, however; being thorough from a technical point-of-view has two advantages. First he gets the respect of his team and hence they listen to him. Second, the developers always have someone to talk to when faced with a technical issue. &lt;br /&gt;&lt;br /&gt;An architect should be a programmer at heart. This doesn’t necessarily mean that he writes production code, however; coding is a norm for him. A personal project or small business application can keep him on his toes. &lt;br /&gt;&lt;br /&gt;One trait of an architect is to experiment with different technology. An architect’s search for cutting edge technology leads to user friendly business applications which are a boost for the business. &lt;br /&gt;&lt;br /&gt;One important trait of an architect is to remember the basics of his IT education. Over the years, software architects forget about basics including data structures, databases, software engineering etc. A good architect remembers the basics which help him better design and implement software systems.&lt;br /&gt;&lt;br /&gt;Last but not the least is that an architect always comes with a working prototype of the system to be developed. This simple point cannot be emphasized enough. A working prototype is critical in convincing the top management, ensuring user satisfaction and communicating with team members. The prototype doesn’t need to be a complete application. But it must show the big picture to all the stakeholders involved. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Problem Solving Skills&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;One question often asked by under-training architects is that do they need to know design patterns and software methodologies. The answer is both yes and no. Every designer handles a problem differently but proven best practices have their weight. They reduce the overall complexity and are optimized for performance. An architect may have good problem solving skills, however; knowing best practices always goes in his favor. &lt;br /&gt;&lt;br /&gt;There is a saying that any solution which can be expressed in numbers is better than others. An architect evaluates his design and solution from a complexity point of view. For example, he may use Line of Codes (LoC) to determine the complexity of the code. Breaking the system into subparts and applying different complexity matrices allows him to perform a systematic evaluation of the system. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Personality Traits&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;As an architect, every developer must adapt some personality traits at an early stage of his career. He has the urge to ask ‘WHY’. Talking to different people within an organization lets him understand the business strategy. A good architect is often spotted talking to users and taking notes. This trait makes him different from the ‘Average Joe’.&lt;br /&gt;&lt;br /&gt;When designing a system, an architect follows values principles such as conforming to standards, applying best practices and adhering to architectural values. For example, even if he is tasked to design a small application in limited amount of time, the application has a proper architecture. He understands that every application grows over time and becomes a maintenance nightmare if not architected properly. &lt;br /&gt;&lt;br /&gt;I hope that in this post, you have learnt along the lines. Do share your thoughts on this. Stay tuned for more…&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/834688215084300455-5357050392176081137?l=dotnetpost.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetpost.blogspot.com/feeds/5357050392176081137/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetpost.blogspot.com/2010/03/software-architect.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/5357050392176081137'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/5357050392176081137'/><link rel='alternate' type='text/html' href='http://dotnetpost.blogspot.com/2010/03/software-architect.html' title='Software Architect'/><author><name>Kashif Ahmad</name><uri>http://www.blogger.com/profile/02151423871584093787</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-834688215084300455.post-7436369192989758199</id><published>2010-03-05T11:09:00.000-08:00</published><updated>2010-03-09T10:11:12.879-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tech-Ed MEA'/><title type='text'>Microsoft Tech-Ed 2010 Middle-East Conference</title><content type='html'>&lt;br&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;I have just returned from &lt;a href="http://www.teched.ae/"&gt;Microsoft Tech-Ed Middle-East 2010&lt;/a&gt; conference. This was the first time Tech-Ed was held for the Middle-East region in Dubai. &lt;br /&gt;&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_a0lOQELDZCg/S5FXXRZ8j0I/AAAAAAAAAFU/yyZ05bkXMnc/s1600-h/TechEd+Logo.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 384px; height: 83px;" src="http://1.bp.blogspot.com/_a0lOQELDZCg/S5FXXRZ8j0I/AAAAAAAAAFU/yyZ05bkXMnc/s400/TechEd+Logo.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5445229481788477250" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;It was a wonderful experience attending this conference with Microsoft’s top IT gurus around. Personally I was delighted to meet &lt;a href="http://www.hanselman.com/"&gt;Scott Hanselman&lt;/a&gt; and &lt;a href="http://www.pluralsight.com/community/blogs/aaron/default.aspx"&gt;Aaron Skonnard&lt;/a&gt;. Both these guys are top .NET Professionals in the industry. Not only they are very friendly, they relayed a plethora of information to Tech-Ed attendents. I was thoroughly impressed by Scott Hanselman who has a humorous and unique style of delivering the presentations. &lt;br /&gt;&lt;br /&gt;In the next few days, I will be blogging about some of the cool stuff I learnt at Tech-Ed. So stay tuned for more…&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/834688215084300455-7436369192989758199?l=dotnetpost.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetpost.blogspot.com/feeds/7436369192989758199/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetpost.blogspot.com/2010/03/microsoft-tech-ed-2010-middle-east.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/7436369192989758199'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/7436369192989758199'/><link rel='alternate' type='text/html' href='http://dotnetpost.blogspot.com/2010/03/microsoft-tech-ed-2010-middle-east.html' title='Microsoft Tech-Ed 2010 Middle-East Conference'/><author><name>Kashif Ahmad</name><uri>http://www.blogger.com/profile/02151423871584093787</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_a0lOQELDZCg/S5FXXRZ8j0I/AAAAAAAAAFU/yyZ05bkXMnc/s72-c/TechEd+Logo.jpg' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-834688215084300455.post-5478810567884669669</id><published>2010-01-31T10:15:00.000-08:00</published><updated>2010-03-09T10:10:27.636-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='General'/><title type='text'>ASP.NET 4.0 Quick Video Series</title><content type='html'>&lt;span style="font-family:Verdana;"&gt;&lt;br /&gt;If you are interested in learning ASP.NET 4.0 without spending many hours (and money of course :) reading books, then you must follow the ASP.NET 4.0 'Quick Hit' video series at the official ASP.NET site. The link to this series is &lt;a href="http://www.asp.net/learn/aspnet-4-quick-hit-videos"&gt;Video Series&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Hope this helps...&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/834688215084300455-5478810567884669669?l=dotnetpost.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/5478810567884669669'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/5478810567884669669'/><link rel='alternate' type='text/html' href='http://dotnetpost.blogspot.com/2010/01/aspnet-40-quick-video-series.html' title='ASP.NET 4.0 Quick Video Series'/><author><name>Kashif Ahmad</name><uri>http://www.blogger.com/profile/02151423871584093787</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author></entry><entry><id>tag:blogger.com,1999:blog-834688215084300455.post-4254791753120922941</id><published>2010-01-31T09:58:00.000-08:00</published><updated>2010-03-09T10:08:34.407-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Database'/><title type='text'>Connecting to Remote SQL Server Instance</title><content type='html'>&lt;span style="font-family:Verdana;"&gt;&lt;br /&gt;From time to time, we need to connect to remote SQL Server 2005 instances. Connecting to a local SQL Server instance is simple but if you have made a fresh SQL Server installation and you try to connect it remotely, chances are that your attempt may fail.&lt;br /&gt;&lt;br /&gt;You might think that this can be a simple task. All you have to do is simply check the "Allow Remote Connection" under the properties of the particular SQL Server instance. However, this will still not work.&lt;br /&gt;&lt;br /&gt;The solution is to use &lt;i&gt;SQL Server Configuration Manager&lt;/i&gt;. You can do so by clicking on &lt;b&gt;Start -&gt; Programs -&gt; Microsoft SQL Server -&gt; Configuration Tools -&gt; SQL Server Configuration Manager&lt;/b&gt;. When the manager opens up, in the right pane, click on &lt;b&gt;SQL Native Client Configuration -&gt; Client Protocols&lt;/b&gt;. In the right pane, right click &lt;b&gt;Named Pipes&lt;/b&gt; and select 'Enable'.&lt;br /&gt;&lt;br /&gt;Thats all you need. Now when you connect to the remote instance, you will do so without any difficulty.&lt;br /&gt;&lt;br /&gt;Hope this helps. Stay tunned for more...&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/834688215084300455-4254791753120922941?l=dotnetpost.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetpost.blogspot.com/feeds/4254791753120922941/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetpost.blogspot.com/2010/01/connting-to-remote-sql-server-instance.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/4254791753120922941'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/4254791753120922941'/><link rel='alternate' type='text/html' href='http://dotnetpost.blogspot.com/2010/01/connting-to-remote-sql-server-instance.html' title='Connecting to Remote SQL Server Instance'/><author><name>Kashif Ahmad</name><uri>http://www.blogger.com/profile/02151423871584093787</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-834688215084300455.post-2443886839644166822</id><published>2009-12-31T12:31:00.000-08:00</published><updated>2009-12-31T12:46:05.816-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Software Architecture'/><title type='text'>Types of Data Models</title><content type='html'>&lt;br&gt;&lt;br /&gt;This post talks about the different types of data models we create when working with databases. The different data models include:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Conceptual Data Model&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;&lt;br /&gt;In this model, an Entity Relationship Diagram (ERD) is created. This diagram identifies all the entities in the system. In addition to it, it also defines the relationship between these entities.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Logical Data Model&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;&lt;br /&gt;In this model, the data is normalized. Normalization is the process of converting  complex data structure into simple one. In this model, data is arranged properly in tables and Primary Keys (identifiers) are identified. Also relationships (based on ERD) is defined amongst tables.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Physical Data Model&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;&lt;br /&gt;In this model, the Logical Model is mapped to the target database technology. The schema is defined which includes the attributes, primary keys, forign keys and relationships. &lt;br /&gt;&lt;br /&gt;Hope this helps. Stay tuned for more...&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/834688215084300455-2443886839644166822?l=dotnetpost.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetpost.blogspot.com/feeds/2443886839644166822/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetpost.blogspot.com/2009/12/types-of-data-models.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/2443886839644166822'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/2443886839644166822'/><link rel='alternate' type='text/html' href='http://dotnetpost.blogspot.com/2009/12/types-of-data-models.html' title='Types of Data Models'/><author><name>Kashif Ahmad</name><uri>http://www.blogger.com/profile/02151423871584093787</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-834688215084300455.post-2726207608547288462</id><published>2009-12-31T12:11:00.000-08:00</published><updated>2009-12-31T12:24:07.871-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SharePoint'/><title type='text'>Windows SharePoint Services vs Microsoft Office SharePoint Server</title><content type='html'>&lt;span style="font-family:Verdana;"&gt;&lt;br /&gt;In this post, I will try to explain the difference between Windows Sharepoint Services (WSS) and Microsoft Office Sharepoint Server. People new to Sharepoint tend to use both terms interchangeably. However, these are two different products (although they are inter-related). In the following section, we will see the difference between the two.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Windows Sharepoint Services (WSS)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;&lt;br /&gt;WSS is a part of Windows Server Technology including Server 2003 and 2008. It has to be installed separately and requires IIS 6.0+ and .NET 3.0 framework. After you have installed WSS, you have access to the following features:&lt;br /&gt;&lt;br /&gt;• Sites, Lists&lt;br /&gt;• Blogs, RSS Feeds&lt;br /&gt;• Alerts, Workflows&lt;br /&gt;• Creating Team Sites&lt;br /&gt;• Document Management&lt;br /&gt;&lt;br /&gt;The WSS also integrates with other Microsoft Office products including Outlook, Excel etc. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Microsoft Office Sharepoint Server (MOSS)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;&lt;br /&gt;MOSS is a separate product offered under the Microsoft Office Umbrella. We have to purchase a separate license for this product. In addition to features provided by WSS, MOSS offers the following additional features:&lt;br /&gt;&lt;br /&gt;• Business Intelligence&lt;br /&gt;• Business Data Catalog&lt;br /&gt;• Business Data Web Parts&lt;br /&gt;• MySites (customizable personal sites for users)&lt;br /&gt;• Advanced Workflows&lt;br /&gt;• Policies&lt;br /&gt;• Content Authoring&lt;br /&gt;&lt;br /&gt;You can download the above two products from the following links:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://technet.microsoft.com/en-us/windowsserver/sharepoint/bb400747.aspx"&gt;WSS with SP&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=2E6E5A9C-EBF6-4F7F-8467-F4DE6BD6B831&amp;displaylang=en"&gt;MOSS 2007 Trial Version with SP2&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Stay tuned for more...&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/834688215084300455-2726207608547288462?l=dotnetpost.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetpost.blogspot.com/feeds/2726207608547288462/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetpost.blogspot.com/2009/12/windows-sharepoint-services-vs.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/2726207608547288462'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/2726207608547288462'/><link rel='alternate' type='text/html' href='http://dotnetpost.blogspot.com/2009/12/windows-sharepoint-services-vs.html' title='Windows SharePoint Services vs Microsoft Office SharePoint Server'/><author><name>Kashif Ahmad</name><uri>http://www.blogger.com/profile/02151423871584093787</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-834688215084300455.post-2221168971544849579</id><published>2009-12-28T10:38:00.000-08:00</published><updated>2009-12-31T12:24:56.436-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='General'/><title type='text'>Windows Vista SP2 to the rescue</title><content type='html'>&lt;br&gt;&lt;br /&gt;If you are one of Windows Vista users and have been pulling your hair due to performance issue then you should install Windows Vista SP2 immediately. You can download it from the following link:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=a4dd31d5-f907-4406-9012-a5c3199ea2b3&amp;displaylang=en"&gt;Windows Vista SP2&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;I installed it recently, stopped a few Startup services and have stopped complaining about Vista ever since (Good work Microsoft - a bit late though)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/834688215084300455-2221168971544849579?l=dotnetpost.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetpost.blogspot.com/feeds/2221168971544849579/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetpost.blogspot.com/2009/12/windows-vista-sp2-to-rescue.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/2221168971544849579'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/2221168971544849579'/><link rel='alternate' type='text/html' href='http://dotnetpost.blogspot.com/2009/12/windows-vista-sp2-to-rescue.html' title='Windows Vista SP2 to the rescue'/><author><name>Kashif Ahmad</name><uri>http://www.blogger.com/profile/02151423871584093787</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-834688215084300455.post-157149368828480981</id><published>2009-12-24T06:21:00.000-08:00</published><updated>2009-12-31T12:25:04.371-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET'/><title type='text'>Running ASP.NET 2.0 under IIS 7.0</title><content type='html'>&lt;br&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;In this post, I will share my experience of running ASP.NET 2.0 applications under IIS 7.0. If you run an ASP.NET 2.0 application under IIS 7.0, you will get a &lt;b&gt;&lt;i&gt;500 – Internal Server Error&lt;/i&gt;&lt;/b&gt;. This will occur since IIS 7.0 has got a new enhanced architecture.&lt;br /&gt;&lt;br /&gt;In earlier versions of IIS (6.0 and below), asp.net applications run under IIS through ISAPI extensions. These extensions have their own processing model and every request must go through this model (or pipeline). In addition to this pipeline, an asp.net application has its own request pipeline (handlers) which processes user requests. This results in two pipelines being exposed. One for ISAPI extensions and other for managed applications.&lt;br /&gt;&lt;br /&gt;IIS 7.0 merges the two pipelines into one &lt;i&gt;Integrated Managed Pipeline&lt;/i&gt; which handles both native and managed request. This provides added features to the developers. For example, many of .NET features such as Authentication, Authorization can be applied to images, scripts and other files which may come under ISAPI extensions. Similarly, URL Rewriting is powerful feature added to IIS 7.0 to help write SEO URLs.&lt;br /&gt;&lt;br /&gt;Due to the above mentioned architecture, asp.net 2.0 applications do not run under IIS 7.0 out of the box. IIS will give a &lt;i&gt;500 – Internal Server Error&lt;/i&gt; when trying to browse the application. The solution to fix this problem is described in the following sections. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Change settings in web.config file&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;In this solution, we have to change a few settings in the web.config file. This is done by doing the following steps:&lt;br /&gt;&lt;br /&gt;• Move entries in &amp;lt;system.web&gt;/&amp;lt;httpModules&amp;gt; to &amp;lt;system.webServer&amp;gt;/&amp;lt;modules&amp;gt;&lt;br /&gt;• Move entries in &amp;lt;system.web&amp;gt;/&amp;lt;httpHandlers&amp;gt; to &amp;lt;system.webServer&amp;gt;/&amp;lt;handlers&amp;gt;&lt;br /&gt;&lt;br /&gt;In addition to this, also add the following entry under the &amp;lt;system.web&amp;gt; section:&lt;br /&gt;&lt;br /&gt; &amp;lt;system.webServer&amp;gt;&lt;br /&gt;      &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;validation validateIntegratedModeConfiguration="false" /&amp;gt;&lt;br /&gt;&amp;lt;/system.webServer&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Change Application Pools setting in IIS &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;This solution is easier to follow however; this applies to all applications running under IIS and hence prevents from taking advantages of the new IIS features. In this case changes are made in IIS Manager by the following steps:&lt;br /&gt;&lt;br /&gt;Start IIS Manager and select ‘Applications Pool’. &lt;br&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_a0lOQELDZCg/SzN5RmoScjI/AAAAAAAAAE4/EUMoa5LUCjM/s1600-h/1.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 400px; height: 79px;" src="http://2.bp.blogspot.com/_a0lOQELDZCg/SzN5RmoScjI/AAAAAAAAAE4/EUMoa5LUCjM/s400/1.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5418808119991104050" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;In the top right corner, click on ‘Set Application Pool Defaults’. This will display the Application Pool Defaults dialog. &lt;br&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_a0lOQELDZCg/SzN5ef772lI/AAAAAAAAAFA/TI0UMPoIEUQ/s1600-h/2.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 327px; height: 400px;" src="http://2.bp.blogspot.com/_a0lOQELDZCg/SzN5ef772lI/AAAAAAAAAFA/TI0UMPoIEUQ/s400/2.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5418808341532760658" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;For the ‘Managed Pipeline Mode’ property, select ‘Classic’ and close the dialog.&lt;br&gt;&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_a0lOQELDZCg/SzN5ogTR19I/AAAAAAAAAFI/fCtb7urQoh4/s1600-h/3.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 327px; height: 400px;" src="http://1.bp.blogspot.com/_a0lOQELDZCg/SzN5ogTR19I/AAAAAAAAAFI/fCtb7urQoh4/s400/3.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5418808513429362642" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Now when you browse your asp.net 2.0 application, you must be able to run it successfully. Stay tuned for more. &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/834688215084300455-157149368828480981?l=dotnetpost.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetpost.blogspot.com/feeds/157149368828480981/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetpost.blogspot.com/2009/12/running-aspnet-20-under-iis-70.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/157149368828480981'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/157149368828480981'/><link rel='alternate' type='text/html' href='http://dotnetpost.blogspot.com/2009/12/running-aspnet-20-under-iis-70.html' title='Running ASP.NET 2.0 under IIS 7.0'/><author><name>Kashif Ahmad</name><uri>http://www.blogger.com/profile/02151423871584093787</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_a0lOQELDZCg/SzN5RmoScjI/AAAAAAAAAE4/EUMoa5LUCjM/s72-c/1.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-834688215084300455.post-8382856876428547984</id><published>2009-12-24T06:20:00.001-08:00</published><updated>2009-12-31T12:25:12.790-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='General'/><title type='text'>XCopy and Insufficient Memory Error</title><content type='html'>&lt;br&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;Recently I came across an interesting situation pertaining to XCopy so I thought of sharing my experience with you. As part of my daily backup procedure, I use the MS-DOS based XCopy command in a .bat file (scheduled) to copy over a large number of files from one machine to the other. The XCopy command has been working fine ever since until recently I noticed that the entire data was not copied over. &lt;br /&gt;&lt;br /&gt;I ran the .bat file manually to see what was going on. After some time, the command window displayed the following message:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Insufficient Memory…&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;I was using a powerful machine and memory (RAM) was not an issue. After doing some googling, I finally figured out the source of the problem which had nothing to do (at least in my case) with having enough memory. The problem was a long file name which didn’t allow the XCopy command to run to completion. You must be surprised but read on.&lt;br /&gt;&lt;br /&gt;The XCopy command fails to handle a fully qualified filename (filename + path) which is greater than 254 characters (which is by the way also the maximum path length allowed by Microsoft OS). The message &lt;b&gt;Insufficient Memory…&lt;/b&gt; is very misleading and doesn’t reveal the actual problem. &lt;br /&gt;&lt;br /&gt;I went ahead to shorten the name of a few files which fixed the problem. But if this is not the desired solution for you then you can look into using XXCopy (commercial) or Robocopy (free - Microsoft). Although I haven’t used any of these, I have seen some people complaining about XXCopy still not doing the job. Robocopy on the other hand, seem to be a suitable solution. So you can try your luck with that (if you don’t want to shorten the filename :- ).&lt;br /&gt;&lt;br /&gt;Stay tuned for more…&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/834688215084300455-8382856876428547984?l=dotnetpost.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetpost.blogspot.com/feeds/8382856876428547984/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetpost.blogspot.com/2009/12/xcopy-and-insufficient-memory-error.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/8382856876428547984'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/8382856876428547984'/><link rel='alternate' type='text/html' href='http://dotnetpost.blogspot.com/2009/12/xcopy-and-insufficient-memory-error.html' title='XCopy and Insufficient Memory Error'/><author><name>Kashif Ahmad</name><uri>http://www.blogger.com/profile/02151423871584093787</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-834688215084300455.post-1449955654846580847</id><published>2009-12-18T10:37:00.001-08:00</published><updated>2009-12-18T22:13:06.718-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET'/><title type='text'>IIS 7.0 and HTTP Errors</title><content type='html'>&lt;br&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;Recently I have been working with Internet Information Server (IIS) 7.0 and got into a few issues (obviously due to my lack of knowledge :-). I configured an ‘Application’ under the ‘Default Web Site’ but was unable to run it. Adding to it, I only got the following error message which gave no clue of what the problem was:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;HTTP Error 500 - Internal Server Error&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;I unchecked the &lt;i&gt;Show friendly HTTP error messages&lt;/i&gt; option in Internet Explorer (you can do so in IE by going to Tools -&gt; Internet Options -&gt; Advanced (tab) -&gt; under Browsing) but to my frustration, this time I got a completely blank screen (no error at all :-). After doing some research, it dawned on me that I had not turned on the &lt;i&gt;HTTP Error &lt;/i&gt; feature when I installed IIS 7.0. So I went ahead to install this feature (it is found under &lt;i&gt;Web Server -&gt; Common IIS Features -&gt; HTTP Features -&gt; HTTP Error&lt;/i&gt; when installing IIS). With this feature installed, you can see an &lt;i&gt;Error Pages&lt;/i&gt; (shown below) icon in IIS Manager.&lt;br /&gt;&lt;br /&gt;After turning on the &lt;i&gt;HTTP Error&lt;/i&gt; feature, there is one more step needed before you can see the proper error message. In IIS Manager, click on &lt;i&gt; Default Web Site&lt;/i&gt; and select the &lt;i&gt;Error Pages&lt;/i&gt; feature as shown below:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_a0lOQELDZCg/SyvMHNnMbGI/AAAAAAAAAEY/pG_nq2C-fnY/s1600-h/ErrorPages.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 400px; height: 290px;" src="http://2.bp.blogspot.com/_a0lOQELDZCg/SyvMHNnMbGI/AAAAAAAAAEY/pG_nq2C-fnY/s400/ErrorPages.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5416647401128356962" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;This will bring you to another screen where you click on &lt;i&gt;Edit Features Settings&lt;/i&gt; as shown below:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_a0lOQELDZCg/SyvMQlTCPUI/AAAAAAAAAEg/e8AhYSDBSaI/s1600-h/EditFeatureSettings.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 400px; height: 81px;" src="http://2.bp.blogspot.com/_a0lOQELDZCg/SyvMQlTCPUI/AAAAAAAAAEg/e8AhYSDBSaI/s400/EditFeatureSettings.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5416647562105077058" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Next you will see a &lt;i&gt;Edit Error Pages Settings&lt;/i&gt; dialog box. Make sure the option &lt;i&gt;Detailed errors for local requests and custom error pages for remote request&lt;/i&gt; option is selected as shown below:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_a0lOQELDZCg/SyvMe462FfI/AAAAAAAAAEo/zKxCpbZ0TVQ/s1600-h/SettingsDialog.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 396px; height: 365px;" src="http://3.bp.blogspot.com/_a0lOQELDZCg/SyvMe462FfI/AAAAAAAAAEo/zKxCpbZ0TVQ/s400/SettingsDialog.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5416647807890494962" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Now when I browsed my application, I was delighted to see the error message (had to fix it though :-) as shown below:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_a0lOQELDZCg/SyvMsjj6biI/AAAAAAAAAEw/U8i0A8eGBm8/s1600-h/Error1.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 400px; height: 339px;" src="http://2.bp.blogspot.com/_a0lOQELDZCg/SyvMsjj6biI/AAAAAAAAAEw/U8i0A8eGBm8/s400/Error1.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5416648042675334690" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Detailed vs. Custom Errors&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;IIS 7.0 either displays a Custom or a Detailed error message based on the type of request. A ‘Custom Message’ is displayed to a client accessing the website from a remote location. This is a short user-friendly message which doesn’t reveal any information pertaining to the website.&lt;br /&gt;&lt;br /&gt;A Detailed error message, on the other hand, is displayed when browsing locally (the same machine). Usually the developer or the admin would need to do that for debugging purpose. This type of error message is more verbose and informative which helps in debugging the application. A detailed message would look like the one shown above. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Hope this was useful. Stay tuned for more...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/834688215084300455-1449955654846580847?l=dotnetpost.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetpost.blogspot.com/feeds/1449955654846580847/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetpost.blogspot.com/2009/12/recently-i-have-been-working-with.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/1449955654846580847'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/1449955654846580847'/><link rel='alternate' type='text/html' href='http://dotnetpost.blogspot.com/2009/12/recently-i-have-been-working-with.html' title='IIS 7.0 and HTTP Errors'/><author><name>Kashif Ahmad</name><uri>http://www.blogger.com/profile/02151423871584093787</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_a0lOQELDZCg/SyvMHNnMbGI/AAAAAAAAAEY/pG_nq2C-fnY/s72-c/ErrorPages.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-834688215084300455.post-8389932158248748174</id><published>2009-11-26T12:50:00.001-08:00</published><updated>2009-12-18T10:45:14.608-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='LINQ'/><title type='text'>LINQ Explained - Index</title><content type='html'>&lt;br&gt;&lt;br /&gt;For your convenience, I am adding the following index of my on going series on Language Integrated Query or LINQ.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;&lt;a href="http://dotnetpost.blogspot.com/2008/10/linq-explained-part-1.html"&gt;LINQ Explained - 1&lt;/a&gt;: Introduction to LINQ&lt;br /&gt;&lt;a href="http://dotnetpost.blogspot.com/2008/12/linq-explained-part-2.html"&gt;LINQ Explained - 2&lt;/a&gt;: Features used by LINQ&lt;br /&gt;&lt;a href="http://dotnetpost.blogspot.com/2009/03/linq-explained-part-3.html"&gt;LINQ Explained - 3&lt;/a&gt;: Some more features used by LINQ&lt;br /&gt;&lt;a href="http://dotnetpost.blogspot.com/2009/11/linq-explained-part-4.html"&gt;LINQ Explained - 4&lt;/a&gt;: LINQ Syntax&lt;br /&gt;LINQ Explained - 5: LINQ to SQL&lt;br /&gt;LINQ Explained - 6: LINQ to Objects&lt;br /&gt;LINQ Explained - 7: LINQ to XML&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/834688215084300455-8389932158248748174?l=dotnetpost.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetpost.blogspot.com/feeds/8389932158248748174/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetpost.blogspot.com/2009/11/linq-explained-index.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/8389932158248748174'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/8389932158248748174'/><link rel='alternate' type='text/html' href='http://dotnetpost.blogspot.com/2009/11/linq-explained-index.html' title='LINQ Explained - Index'/><author><name>Kashif Ahmad</name><uri>http://www.blogger.com/profile/02151423871584093787</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-834688215084300455.post-2351994357694492269</id><published>2009-11-26T12:39:00.000-08:00</published><updated>2009-12-18T10:45:14.608-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='LINQ'/><title type='text'>LINQ Explained – Part 4</title><content type='html'>&lt;br&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;This is the fourth part of my on-going series on Language Integrated Query or LINQ. I have been away from this series for a while. However my following posts (including this one) are aimed at completing this series. In the &lt;a href="http://dotnetpost.blogspot.com/2008/12/linq-explained-part-2.html"&gt;second&lt;/a&gt; and &lt;a href="http://dotnetpost.blogspot.com/2009/03/linq-explained-part-3.html"&gt;third&lt;/a&gt; posts, we had an overview of the features which are important to understand to have a full grasp of LINQ. In this post, we will have a detailed look at LINQ syntax and explore its different features. So let us get started. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Introduction&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;LINQ is a set of language extensions added to C# and VB.NET which makes queries a first-class concept to these languages. It provides a unified programming model to different data domains for data management. As I mentioned in my &lt;a href="http://dotnetpost.blogspot.com/2008/10/linq-explained-part-1.html"&gt;first&lt;/a&gt; post, using LINQ we can query and operate on different data domains including relational databases, XML, custom entities, DataSets or any third party data source. Above all, the concept of queries is now applicable to in-memory data as opposed to using queries with a persistent medium only. From a developer’s point of view, the interface to each data domain remains the same. But the LINQ engine is responsible for converting the queries to target the domain being referenced. &lt;br /&gt;&lt;br /&gt;Since LINQ is a first-class concept in C# and VB.NET, these languages come loaded with support for LINQ. LINQ queries take advantage of features including IntelliSence and compile-time syntax checking. LINQ queries rely on &lt;i&gt;standard query operators&lt;/i&gt; (discussed shortly) which are a set of functions used to fetch, parse, sort and filter the data. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Query Expression and Method-Based Queries&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;A LINQ query is a reminiscent of standard SQL-Query syntax. The purpose of LINQ is to add data querying capabilities to the .NET Framework such that any data-domain can be processed with the same ease. LINQ relies on concepts including Extension Methods, Anonymous Types, Anonymous Methods and Lambda Expressions discussed in earlier posts.&lt;br /&gt;&lt;br /&gt;A LINQ Query is also known as &lt;b&gt;&lt;i&gt;Query Expression&lt;/i&gt;&lt;/b&gt; or &lt;b&gt;&lt;i&gt;Query Syntax&lt;/i&gt;&lt;/b&gt;. A query expression is a declarative syntax for writing queries which allows us to filter, group and order data. According to MSDN, &lt;i&gt;“a query expression operates on one or more information sources by applying one or more query operators from either the standard query operators or domain-specific operators”&lt;/i&gt;. This means that LINQ can operate on different data-domains using operators specific to LINQ or developed by a third party. To me this is a polymorphic behavior of LINQ. The result of a query expression is an in-memory sequence of elements (or objects). Any object which implements the IEnumerable &amp;lt;T&amp;gt; interface is a sequence. The resultant sequence can be iterated through by built-in language iterators. &lt;br /&gt;&lt;br /&gt;Let us see a simple example in listing 1 which shows a LINQ Query in action:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Listing 1&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;int [] prime = new int [8] {1, 3, 5, 7, 11, 13, 17, 19}; // Line 1&lt;br /&gt;&lt;br /&gt;var primeNumbers =  // Line 2&lt;br /&gt;        from p in prime      // Line 3&lt;br /&gt;        where p &amp;gt; 0         // Line 4&lt;br /&gt;        select p;            // Line 5&lt;br /&gt;&lt;br /&gt;foreach (int p in primeNumbers) // Line 6&lt;br /&gt;{&lt;br /&gt;    // use p&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;In the above listing, a list of prime numbers is queried and the result is assigned to a variable &lt;i&gt;primeNumbers&lt;/i&gt;. The LINQ Query (line 2–5) resembles a SQL statement with the standard &lt;i&gt;from, where and select&lt;/i&gt; clauses. But it is being applied to an in-memory collection of numbers rather than a persistent medium (such as database or XML). Although simple but I am sure you can visualize the strength of LINQ upfront from the above example. The rest of the example is what we talked about (var, foreach) in the &lt;a href="http://dotnetpost.blogspot.com/2009/03/linq-explained-part-3.html"&gt;previous&lt;/a&gt; post. &lt;br /&gt;&lt;br /&gt;A query expression can also be represented by a &lt;b&gt;&lt;i&gt;Method-based Query&lt;/i&gt;&lt;/b&gt; syntax. A method-based query utilizes extension methods and lambda expression. It is a rather concise way of writing query expressions. There is no performance difference between the two. A query expression is more readable while a method-based query is concise to write. It really comes down to your choice of syntax. &lt;b&gt;&lt;i&gt;But do keep in mind that all query expressions are translated into method-based queries&lt;/i&gt;&lt;/b&gt;. Using method-based query, listing 1 can be written as following:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Listing 2&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;IEnumerable &amp;lt;int&amp;gt; primeNumbers =&lt;br /&gt;                                    prime           &lt;br /&gt;                                    .Where (p =&amp;gt; p &gt; 0)&lt;br /&gt;                                    .Select  (p =&amp;gt; p);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;Avid readers must have figured out the reason for applying the &lt;i&gt;foreach&lt;/i&gt; loop on the variable primeNumbers in listing 1. This is because the type &lt;i&gt;primeNumbers&lt;/i&gt; is converted to IEnumerable &amp;lt;T&amp;gt; which represents a collection of elements. This collection be iterated using &lt;i&gt;foreach&lt;/i&gt; loop. &lt;br /&gt;&lt;br /&gt;I am sure by now you can spot many of the features explained in &lt;a href="http://dotnetpost.blogspot.com/2008/12/linq-explained-part-2.html"&gt;part 2&lt;/a&gt; and &lt;a href="http://dotnetpost.blogspot.com/2009/03/linq-explained-part-3.html"&gt;part 3&lt;/a&gt; of this series. The above queries are just making use of concepts including var keyword, extension methods, lambda expressions and enumerators. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;LINQ Syntax&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;LINQ is a reminiscent of standard SQL Language and thus has a sharp resemblance to it. Like its counterpart, query expression consists of clauses. There are three main clauses in a LINQ expression including &lt;i&gt;from&lt;/i&gt;, &lt;i&gt;select&lt;/i&gt; and the &lt;i&gt;where&lt;/i&gt; clause. The general syntax of a LINQ query is as following:&lt;br /&gt;&lt;br /&gt;var [query] =   from …&lt;br /&gt;          where …&lt;br /&gt;          select …&lt;br /&gt;&lt;br /&gt;The first clause in a LINQ Query is the &lt;i&gt;from&lt;/i&gt; clause. You may be wondering why a LINQ query begins with the &lt;i&gt;from&lt;/i&gt; clause unlike a standard SQL query which is preceded by the &lt;i&gt;select&lt;/i&gt; clause. The reason for this precedence is to support Intellisence when working with Visual Studio IDE. Since the &lt;i&gt;from&lt;/i&gt; clause specifies the data source ahead of the query, the compiler becomes data-source aware and hence supports Intellisence. The &lt;i&gt;from&lt;/i&gt; clause is then followed by the &lt;i&gt;where&lt;/i&gt; and &lt;i&gt;select&lt;/i&gt; clauses. You can find the full syntax of a LINQ Query &lt;a href="http://msdn.microsoft.com/en-us/library/bb308959.aspx"&gt;here &lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Let us see listing 3 to analyze a LINQ query piece by piece. We start by defining a simple class followed by object initialization:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Listing 3&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;public class Car&lt;br /&gt;{&lt;br /&gt;        public string Type { get; set; }&lt;br /&gt;        public string Color { get; set; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Car[] cars = &lt;br /&gt;{&lt;br /&gt;        new Car { Type = "SUV",   Color = "Green" }, &lt;br /&gt;        new Car { Type = "SUV",   Color = "Black" }, &lt;br /&gt;        new Car { Type = "4x4",   Color = "Red" }, &lt;br /&gt;        new Car { Type = "Truck", Color = "Orange" }, &lt;br /&gt;        new Car { Type = "Jeep",  Color = "Black"}&lt;br /&gt;};      &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;Now that we have an array of cars with their properties initialized, we use a LINQ Query to find all the cars with a specific make: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;IEnumerable&amp;lt;Car&amp;gt; search =&lt;br /&gt;            from myCar in cars&lt;br /&gt;            where myCar.Type == "SUV"&lt;br /&gt;            select myCar;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;The query begins with the &lt;i&gt;from&lt;/i&gt; clause. A &lt;i&gt;from&lt;/i&gt; clause only operates on sequences implementing the &lt;i&gt;IEnumerable&lt;/i&gt; interface. This clause is actually made up of two parts; &lt;i&gt;from&lt;/i&gt; and &lt;i&gt;in&lt;/i&gt;. The &lt;i&gt;in&lt;/i&gt; part points to the source-sequence which must be of type &lt;i&gt;IEnumerable&lt;/i&gt; while the &lt;i&gt;from&lt;/i&gt; part is a variable used for iterating through the source-sequence. &lt;br /&gt;&lt;br /&gt;Next is the &lt;i&gt;where&lt;/i&gt; clause used for filtering. Behind the scene, this clause is converted to &lt;i&gt;Where&lt;/i&gt; Query Operator which is a member of the &lt;i&gt;Enumerable&lt;/i&gt; class. This method accepts a lambda expression as parameter to apply the filter.&lt;br /&gt;&lt;br /&gt;Next in the sequence is the &lt;i&gt;select&lt;/i&gt; clause. This clause defines an expression which is assigned to a variable. The expression can be of any type including an instance of a class, string, number, boolean etc. Indeed this clause lets a type be created on the fly and assigned to a variable.&lt;br /&gt;&lt;br /&gt;Finally, we can iterate through the variable ‘search’ since it is of type &lt;i&gt;IEnumerable&lt;/i&gt; using the following code: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;foreach (Car c in search)&lt;br /&gt;{&lt;br /&gt;// use c.Type, c.Color&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Standard Query Operators&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;So far we have hardly scratched the surface of LINQ syntax and have seen some very simple LINQ queries, but in reality; the discussion of query expressions is incomplete without &lt;b&gt;&lt;i&gt;Standard Query Operators&lt;/i&gt;&lt;/b&gt;. The standard query operators represent an API defined in the &lt;i&gt;Enumerable&lt;/i&gt; and &lt;i&gt;Queryable&lt;/i&gt; classes under the &lt;i&gt;System.Linq&lt;/i&gt; namespace. These operators are extension methods which accept lambda expressions as argument. These operators operate on &lt;b&gt;&lt;i&gt;sequences&lt;/i&gt;&lt;/b&gt; where any object which implements the &lt;i&gt;IEnumerable&amp;lt;T&amp;gt;&lt;/i&gt; interface qualifies for a sequence. These operators are used to traverse, filter, sort, order and perform various functions on the given data. In other words they provide many of the features of a standard SQL Query including Distinct, Group, Set, Order By, Select etc.&lt;br /&gt;&lt;br /&gt;I have stated above that a query expression is converted to a method-based query. &lt;b&gt;In a method-based query, a &lt;i&gt;Clause&lt;/i&gt; is converted to its respective &lt;i&gt;Standard Query Operator (an extension method) &lt;/i&gt;&lt;/b&gt;. For example, the &lt;i&gt;where&lt;/i&gt; clause is converted to a &lt;i&gt;Where&lt;/i&gt; operator while the &lt;i&gt;select&lt;/i&gt; clause is converted to a &lt;i&gt;Select&lt;/i&gt; Operator. To keep it simple, just remember that &lt;i&gt;the same clause in a query expression is represented by an operator when converted to a method-based query&lt;/i&gt;. &lt;br /&gt;&lt;br /&gt;According to LINQ’s official documentation, Standard Query Operators can be categorized into the following:&lt;br /&gt;&lt;br /&gt;• Restriction operators&lt;br /&gt;• Projection operators&lt;br /&gt;• Partitioning operators&lt;br /&gt;• Join operators&lt;br /&gt;• Concatenation operator&lt;br /&gt;• Ordering operators&lt;br /&gt;• Grouping operators&lt;br /&gt;• Set operators&lt;br /&gt;• Conversion operators&lt;br /&gt;• Equality operator&lt;br /&gt;• Element operators&lt;br /&gt;• Generation operators&lt;br /&gt;• Aggregate operators&lt;br /&gt;&lt;br /&gt;A detailed explanation of each of the above is beyond the scope of this post. However, in the following sections, we will look at some of these operators and their use.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Select / SelectMany – Projection Operators&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;A &lt;i&gt;Select&lt;/i&gt; operator performs a projection over a sequence and returns an object of type IEnumerable&amp;lt;T&amp;gt;. When this object is enumerated, it enumerates through the source sequence and produces one output element for each item in the sequence. The signature of the &lt;i&gt;Select&lt;/i&gt; operator is as following:&lt;br /&gt;&lt;br /&gt;public static IEnumerable&amp;lt;S&amp;gt; Select&amp;lt;T, S&amp;gt; (&lt;br /&gt;    this IEnumerable&amp;lt;T&amp;gt; source,&lt;br /&gt;    Func&amp;lt;T, S&amp;gt; selector);&lt;br /&gt;public static IEnumerable&amp;lt;S&amp;gt; Select&amp;lt;T, S&amp;gt; (&lt;br /&gt;    this IEnumerable&amp;lt;T&amp;gt; source,&lt;br /&gt;    Func&amp;lt;T, int, S&amp;gt; selector);&lt;br /&gt;&lt;br /&gt;The first argument of the selector predicate is the &lt;i&gt;source&lt;/i&gt; sequence while the &lt;i&gt;selector&lt;/i&gt; argument is a zero-based index of elements within the source sequence. I will skip an example for this operator as all the above examples make use of this operator :)&lt;br /&gt;&lt;br /&gt;The &lt;i&gt;SelectMany&lt;/i&gt; operator is used with nested sequences or in other words sequence of sequences. It merges all the sub-sequences into one single enumerable sequence. The &lt;i&gt;SelectMany&lt;/i&gt; operator first enumerates the source sequence and converts its respective sub-sequence into an enumerable object. It then enumerates each element in the enumerable object to form a flat sequence. The operator has the following signature:&lt;br /&gt;&lt;br /&gt;public static IEnumerable&amp;lt;S&amp;gt; SelectMany&amp;lt;T, S&amp;gt;(&lt;br /&gt;    this IEnumerable&amp;lt;T&amp;gt; source,&lt;br /&gt;    Func&amp;lt;T, IEnumerable&amp;lt;S&amp;gt; &amp;gt; selector);&lt;br /&gt;public static IEnumerable&amp;lt;S&amp;gt; SelectMany&amp;lt;T, S&amp;gt;(&lt;br /&gt;    this IEnumerable&amp;lt;T&amp;gt; source,&lt;br /&gt;    Func&amp;lt;T, int, IEnumerable&amp;lt;S&amp;gt;&amp;gt; selector);&lt;br /&gt;&lt;br /&gt;The &lt;i&gt;source&lt;/i&gt; is the sequence to be enumerated. The &lt;i&gt;selector&lt;/i&gt; predicate represents the function that that is applied to each element in the sequence. &lt;br /&gt;&lt;br /&gt;Listing 4 shows the use of the &lt;i&gt;SelectMany&lt;/i&gt; operator:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Listing 4&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;public class Region&lt;br /&gt;{&lt;br /&gt;     public int RegionID;&lt;br /&gt;     public string RegionName;&lt;br /&gt;     public List&amp;lt;Product&amp;gt; Products;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public class Product&lt;br /&gt;{&lt;br /&gt;    public string ProductCode;&lt;br /&gt;    public string ProductName;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;Now we will initialize a list of type Region with a child object of type Product: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;List&amp;lt;Region&amp;gt; products = new List&amp;lt;Region&amp;gt;&lt;br /&gt;        {&lt;br /&gt;            new Region { RegionID = 1, RegionName = "North",&lt;br /&gt;                            Products = new List&amp;lt;Product&amp;gt; { &lt;br /&gt;                                    new Product { ProductCode = "EG", ProductName = "Eggs" },&lt;br /&gt;                                    new Product { ProductCode = "OJ", ProductName = "Orange Juice" },&lt;br /&gt;                                    new Product { ProductCode = "BR", ProductName = "Bread" }&lt;br /&gt;                            }&lt;br /&gt;            },&lt;br /&gt;&lt;br /&gt;            new Region { RegionID = 2, RegionName = "South",&lt;br /&gt;                            Products = new List&amp;lt;Product&amp;gt; { &lt;br /&gt;                                    new Product { ProductCode = "CR", ProductName = "Cereal" },&lt;br /&gt;                                    new Product { ProductCode = "HO", ProductName = "Honey" },&lt;br /&gt;                                    new Product { ProductCode = "MI", ProductName = "Milk" },&lt;br /&gt;                            }&lt;br /&gt;            },&lt;br /&gt;&lt;br /&gt;            new Region { RegionID = 3, RegionName = "East",&lt;br /&gt;                            Products = new List&amp;lt;Product&amp;gt; { &lt;br /&gt;                                    new Product { ProductCode = "SO", ProductName = "Soap" },&lt;br /&gt;                                    new Product { ProductCode = "BS", ProductName = "Biscuits" },&lt;br /&gt;                            }&lt;br /&gt;            }&lt;br /&gt;        };&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;Now we apply the &lt;i&gt;SelectMany&lt;/i&gt; operator to select products from the North and East region: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;var ProductsByRegion =&lt;br /&gt;            products&lt;br /&gt;            .Where (p =&amp;gt; p.RegionName == "North" || p.RegionName == "East")&lt;br /&gt;            .SelectMany (p =&amp;gt; p.Products); // using SelectMany operator&lt;br /&gt;&lt;br /&gt;foreach (var product in ProductsByRegion)&lt;br /&gt;{&lt;br /&gt;    string code, name;&lt;br /&gt;&lt;br /&gt;    code = product.ProductCode;&lt;br /&gt;    name = product.ProductName;&lt;br /&gt;    // use code &amp; name&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;The above listing begins by defining two classes, &lt;i&gt;Region&lt;/i&gt; and &lt;i&gt;Product&lt;/i&gt;. The region class consists of a child collection property &lt;i&gt;Products&lt;/i&gt;. Next a list of regions is initialized such that each Region in turn has multiple products. The LINQ Query is applied using the &lt;i&gt;SelectMany&lt;/i&gt; operator. This will flat out the sub-lists (products in this case) for the selected regions (North and East) and create a single sequence to be iterated. If you run the above code, you get the following result:&lt;br /&gt;&lt;br /&gt;EG: Eggs, OJ: Orange Juice, BR: Bread, SO: Soap, BS: Biscuits&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Where– Restriction Operator&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;The &lt;i&gt;Where&lt;/i&gt; operator, also known as restriction operator, filters a sequence based on a condition. The condition is provided as a predicate. The &lt;i&gt;Where&lt;/i&gt; operator enumerates the source sequence and yield those elements for which the predicate returns true. We can also use ‘where’ keyword in place of the &lt;i&gt;Where&lt;/i&gt; operator. The signature for the &lt;i&gt;Where&lt;/i&gt; operator is as follows:&lt;br /&gt;&lt;br /&gt;public static IEnumerable&amp;lt;TSource&amp;gt; Where&amp;lt;TSource&amp;gt;(&lt;br /&gt;    this IEnumerable&amp;lt;TSource&amp;gt; source,&lt;br /&gt;    Func&amp;lt;TSource, bool&amp;gt; predicate);&lt;br /&gt;public static IEnumerable&amp;lt;TSource&amp;gt; Where&amp;lt;TSource&amp;gt;(&lt;br /&gt;    this IEnumerable&amp;lt;TSource&amp;gt; source,&lt;br /&gt;    Func&amp;lt;TSource, int, bool&amp;gt; predicate); &lt;br /&gt;&lt;br /&gt;The &lt;i&gt;source&lt;/i&gt; represents the sequence to be enumerated while the &lt;i&gt;predicate&lt;/i&gt; defines the condition or filter to be applied on the given sequence.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Join / GroupJoin - Join Operators&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;The &lt;i&gt;Join&lt;/i&gt; operator is a counter part of &lt;i&gt;Inner Join&lt;/i&gt; used in SQL Server and serves the same purpose. It returns a sequence of elements from two different sequences with matching keys. This operator has the following signature:&lt;br /&gt;&lt;br /&gt;public static IEnumerable&amp;lt;TResult&amp;gt; Join&amp;lt;TOuter, TInner, TKey, TResult&amp;gt; (&lt;br /&gt;    this IEnumerable&amp;lt;TOuter&amp;gt; outer,&lt;br /&gt;    IEnumerable&amp;lt;TInner&amp;gt; inner,&lt;br /&gt;    Func&amp;lt;TOuter, TKey&amp;gt; outerKeySelector,&lt;br /&gt;    Func&amp;lt;TInner, TKey&amp;gt; innerKeySelector,&lt;br /&gt;    Func&amp;lt;TOuter, TInner, TResult&amp;gt; resultSelector);&lt;br /&gt;public static IEnumerable&amp;lt;TResult&amp;gt; Join&amp;lt;TOuter, TInner, TKey, TResult&amp;gt; (&lt;br /&gt;    this IEnumerable&amp;lt;TOuter&amp;gt; outer,&lt;br /&gt;    IEnumerable&amp;lt;TInner&amp;gt; inner,&lt;br /&gt;    Func&amp;lt;TOuter, TKey&amp;gt; outerKeySelector,&lt;br /&gt;    Func&amp;lt;TInner, TKey&amp;gt; innerKeySelector,&lt;br /&gt;    Func&amp;lt;TOuter, TInner, TResult&amp;gt; resultSelector,&lt;br /&gt;    IEqualityComparer&amp;lt;TKey&amp;gt; comparer);&lt;br /&gt;&lt;br /&gt;In the above overloads, &lt;i&gt;outer&lt;/i&gt; and &lt;i&gt;inner&lt;/i&gt; represent the two source sequences. The predicates &lt;i&gt;outerKeySelector&lt;/i&gt; and &lt;i&gt;innerKeySelector&lt;/i&gt; represent the keys on which the join will be performed. They should be of the same type. The &lt;i&gt;resultSelector&lt;/i&gt; predicate represents the projected result for the final output. In the second overload, we can also use a custom &lt;i&gt;comparer&lt;/i&gt; to perform the join between the two sequences based on custom logic.&lt;br /&gt;&lt;br /&gt;Listing 5 shows the use of &lt;i&gt;Join&lt;/i&gt; operator joins two different lists based on a condition:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Listing 5&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;public class Developer&lt;br /&gt;{&lt;br /&gt;    public string name {get; set; }&lt;br /&gt;    public string projecttitle { get; set; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public class Project&lt;br /&gt;{&lt;br /&gt;    public string title { get; set; }&lt;br /&gt;    public int manDays {get; set; }&lt;br /&gt;    public string company { get; set; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;List&amp;lt;Developer&amp;gt; developers =&lt;br /&gt;                new List&amp;lt;Developer&amp;gt;&lt;br /&gt;                {&lt;br /&gt;                    new Developer { name = "Steven", projecttitle = "ImageProcessing" },&lt;br /&gt;                    new Developer { name = "Markus", projecttitle = "ImageProcessing" },&lt;br /&gt;                    new Developer { name = "Matt",   projecttitle = "ImageProcessing" },&lt;br /&gt;                    new Developer { name = "Shaza",  projecttitle = "GraphicsLibrary" },&lt;br /&gt;                    new Developer { name = "Neil",   projecttitle = "WebArt" },&lt;br /&gt;                };&lt;br /&gt;&lt;br /&gt;        List&amp;lt;Project&amp;gt; projects =&lt;br /&gt;                new List&amp;lt;Project&amp;gt;&lt;br /&gt;                {&lt;br /&gt;                    new Project { title = "ImageProcessing",    company = "Future Vision",  manDays = 120 },&lt;br /&gt;                    new Project { title = "DatabaseFusion",     company = "Open Space",     manDays = 30 },&lt;br /&gt;                    new Project { title = "GraphicsLibrary",    company = "Kid Zone",       manDays = 88  },&lt;br /&gt;                    new Project { title = "WebArt",             company = "Web Ideas",      manDays = 57 },&lt;br /&gt;                    new Project { title = "GamingZone",         company = "Play with Us",   manDays = 50},&lt;br /&gt;                };&lt;br /&gt;&lt;br /&gt;        var ProjectDetails =&lt;br /&gt;            from dev in developers&lt;br /&gt;            join pro in projects&lt;br /&gt;            on dev.projecttitle&lt;br /&gt;            &lt;b&gt;equals&lt;/b&gt; pro.title&lt;br /&gt;            select new&lt;br /&gt;            {&lt;br /&gt;                Programmer = dev.name,&lt;br /&gt;                ProjectName = pro.title,&lt;br /&gt;                Company = pro.company,&lt;br /&gt;                ManHours = pro.manDays&lt;br /&gt;            };&lt;br /&gt;&lt;br /&gt;        foreach (var detail in ProjectDetails)&lt;br /&gt;        {&lt;br /&gt;            // use detail.Programmer, detail.Company, detail.ProjectName, detail.ManHours&lt;br /&gt;        }&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;In the above code, the one thing to notice is the use of ‘equals’ rather then the ‘=’ sign. This is different from what we use in regular sql join statement. The example returns a sequence with matching ‘titiles’ from both sequences.&lt;br /&gt;&lt;br /&gt;The above example works well for a 1:1 mapping between keys. However, if we wanted information on all ‘projects’ irrespective of any matching ‘developer’ then the above query doesn’t work. In a sql environment, a left join would do the trick since it will return all ‘projects’ and matching ‘developer(s)’. However it will return a ‘null’ for all ‘developers’ which do not have an associated ‘project’. In case of LINQ, the same purpose is surved by the &lt;i&gt;GroupJoin&lt;/i&gt; operator.&lt;br /&gt;&lt;br /&gt;The &lt;i&gt;GroupJoin&lt;/i&gt; operator does not return a single sequence of elements  returns a hierarchical sequence of elements. This sequence consists of one element each from the outer sequence. For each element in return, matching elements from the inner sequnce are grouped and attached with it. So it represents a hierarchical grouping of all elements from the outer sequence with each having a child-sequence (grouped together) of matching values from the inner sequence. This operator has the following signature: &lt;br /&gt;&lt;br /&gt;public static IEnumerable&amp;lt;TResult&amp;gt; GroupJoin&amp;lt;TOuter, TInner, TKey,&lt;br /&gt;TResult&amp;gt; (&lt;br /&gt;    this IEnumerable&amp;lt;TOuter&amp;gt; outer,&lt;br /&gt;    IEnumerable&amp;lt;TInner&amp;gt; inner,&lt;br /&gt;    Func&amp;lt;TOuter, TKey&amp;gt; outerKeySelector,&lt;br /&gt;    Func&amp;lt;TInner, TKey&amp;gt; innerKeySelector,&lt;br /&gt;    Func&amp;lt;TOuter, IEnumerable&amp;lt;TInner&amp;gt;, TResult&amp;gt; resultSelector);&lt;br /&gt;public static IEnumerable&amp;lt;TResult&amp;gt; GroupJoin&amp;lt;TOuter, TInner, TKey,&lt;br /&gt;TResult&amp;gt; (&lt;br /&gt;    this IEnumerable&amp;lt;TOuter&amp;gt; outer,&lt;br /&gt;    IEnumerable&amp;lt;TInner&amp;gt; inner,&lt;br /&gt;    Func&amp;lt;TOuter, TKey&amp;gt; outerKeySelector,&lt;br /&gt;    Func&amp;lt;TInner, TKey&amp;gt; innerKeySelector,&lt;br /&gt;    Func&amp;lt;TOuter, IEnumerable&amp;lt;TInner&amp;gt;, TResult&amp;gt; resultSelector,&lt;br /&gt;    IEqualityComparer&amp;lt;TKey&amp;gt; comparer);&lt;br /&gt;&lt;br /&gt;In the above overload, the arguments are similar to the one for the &lt;i&gt;Join&lt;/i&gt; operator but how it works is interested. When the sequence returned by GroupJoin is iterated, it first enumerates through the inner sequence based on the innerKeySelector and groups them together. Grouping elements are stored in a hash table against they key. Next elements from the outer sequence are enumerated based on the outerKeySelector. For each element, matching elements from the hash table are searched. If found, the sequence from the hash table is associated with the element in the outer sequence. This way we get a parent-child grouping of elements. Listing 6 shows how to use &lt;i&gt;GroupJoin&lt;/i&gt; operator (the data sample is from listing 5):&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Listing 6&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;var query = projects.GroupJoin( // outer sequence&lt;br /&gt;                    developers,           // inner sequence &lt;br /&gt;                    p =&amp;gt; p.title,          // outer key selector &lt;br /&gt;                    d =&amp;gt; d.projecttitle, // inner key selector &lt;br /&gt;                    (p, g) =&amp;gt; new&lt;br /&gt;                    {     // result projector&lt;br /&gt;                        ProjectTitle = p.title,&lt;br /&gt;                        Programmers = g&lt;br /&gt;                    });&lt;br /&gt;&lt;br /&gt;foreach (var detail in query)&lt;br /&gt;{&lt;br /&gt;        // use detail.ProjectTitle&lt;br /&gt;        foreach (var programmer in detail.Programmers)&lt;br /&gt;        {&lt;br /&gt;                // use programmer.name, programmer.projecttitle;&lt;br /&gt;        }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;You must have noticed that we are using nested loops to access the elements. This is further proof that the elements are arranged in a parent-child hierarchy such that for each element in the outer sequence, we have matching elements (grouped together) from the inner sequence. The above example will produce the following resultset where all the ‘projects’ are displayed irrespective of a developer(s) assigned to them:&lt;br /&gt;&lt;br /&gt;ImageProcessing&lt;br /&gt; Steven, Markus, Matt&lt;br /&gt;DatabaseFusion&lt;br /&gt;GraphicsLibrary&lt;br /&gt; Shaza&lt;br /&gt;WebArt&lt;br /&gt; Neil&lt;br /&gt;GamingZone&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;OrderBy..ThenBy / OrderByDescending..ThenByDescending - Ordering Operators&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;The &lt;i&gt;OrderBy&lt;/i&gt; operator is used for ordering the elements in a sequence by one or more keys. It also determines the direction of the order i.e. in an ascending order. The signature of this operator is as following:&lt;br /&gt;&lt;br /&gt;public static IOrderedSequence&amp;lt;T&amp;gt; OrderBy&amp;lt;T, K&amp;gt;(&lt;br /&gt; this IEnumerable&amp;lt;T&amp;gt; source,&lt;br /&gt; Func&amp;lt;T, K&amp;gt; keySelector);&lt;br /&gt;public static IOrderedSequence&amp;lt;T&amp;gt; OrderBy&amp;lt;T, K&amp;gt;(&lt;br /&gt; this IEnumerable&amp;lt;T&amp;gt; source,&lt;br /&gt; Func&amp;lt;T, K&amp;gt; keySelector,&lt;br /&gt; IComparer&amp;lt;K&amp;gt; comparer);&lt;br /&gt;&lt;br /&gt;In both the overloads, The &lt;i&gt;source&lt;/i&gt; is the source sequence on which the operator will operator. The &lt;i&gt;keySelector&lt;/i&gt; represents a function that extracts a key of type K from each element of type T from the source sequence. In the second overload, &lt;i&gt;comparer&lt;/i&gt; is a custom comparer where we can write custom code to perform the comparison. &lt;br /&gt;&lt;br /&gt;You must have noticed that the return type of this operator is &lt;i&gt;IOrderedSequence&lt;/i&gt; and not &lt;i&gt;IEnumerable&lt;/i&gt;. Before I explain this, let me mention that  the &lt;i&gt;OrderBy&lt;/i&gt; operator is supported by the &lt;i&gt;ThenBy&lt;/i&gt; operator. In a regular sql command, we can order the resultset by any number of fields in addition to the primary field. The same concept is supported by the &lt;i&gt;ThenBy&lt;/i&gt; operator. The primary ordering is done by the &lt;i&gt;OrderBy&lt;/i&gt; operator followed by the &lt;i&gt;ThenBy&lt;/i&gt; operator. The &lt;i&gt;ThenBy&lt;/i&gt; operator defines the seconary ordering and can be used n-number of times in a LINQ Query. Both operators together work as following:&lt;br /&gt;&lt;br /&gt;source-sequence.OrderBy ().ThenBy ().ThenBy ()…&lt;br /&gt;&lt;br /&gt;The above shows that the output of &lt;i&gt;OrderBy&lt;/i&gt; is input to the &lt;i&gt;ThenBy&lt;/i&gt; operator. Going back to the return type of &lt;i&gt;IOrderedSequence&lt;/i&gt;, the &lt;i&gt;ThenBy&lt;/i&gt; operator can only be applied to &lt;i&gt;IOrderedSequence&lt;/i&gt; and not IEnumerable&amp;lt;T&amp;gt;. For this reason, the return type of &lt;i&gt;OrderBy&lt;/i&gt; operator is &lt;i&gt;IOrderedSequence&lt;/i&gt;. The example in listing 7 will sort the projects by manHours (OrderBy) and then by title (ThenBy):&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Listing 7&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;List&amp;lt;Project&amp;gt; projects =&lt;br /&gt;                new List&amp;lt;Project&amp;gt;&lt;br /&gt;                {&lt;br /&gt;                    new Project { title = "ImageProcessing",    company = "Future Vision",  manDays = 120 },&lt;br /&gt;                    new Project { title = "DatabaseFusion",     company = "Open Space",     manDays = 30 },&lt;br /&gt;                    new Project { title = "GraphicsLibrary",    company = "Kid Zone",       manDays = 88  },&lt;br /&gt;                    new Project { title = "WebArt",             company = "Web Ideas",      manDays = 57 },&lt;br /&gt;                    new Project { title = "GamingZone",         company = "Play with Us",   manDays = 50},&lt;br /&gt;                };&lt;br /&gt;&lt;br /&gt;IEnumerable&amp;lt;Project&amp;gt; details =&lt;br /&gt;    projects.OrderBy (p =&amp;gt; p.manDays).ThenBy (p =&amp;gt; p.title);&lt;br /&gt;&lt;br /&gt;foreach (var project in details)&lt;br /&gt;{&lt;br /&gt;            // use project.manDays , project.title , project.company&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;The concept of ordering can also be achieved by using the &lt;i&gt;OrderByDescending&lt;/i&gt; and &lt;i&gt;ThenByDescending&lt;/i&gt; operators. In this case, as the name implies, the direction of ordering is descending. The signature of &lt;i&gt;OrderByDescending&lt;/i&gt; operator is as following with identical arguments to &lt;i&gt;OrderBy&lt;/i&gt; operator:&lt;br /&gt;&lt;br /&gt;public static OrderedSequence&amp;lt;TSource&amp;gt; OrderByDescending&amp;lt;TSource, TKey&amp;gt;(&lt;br /&gt;    this IEnumerable&amp;lt;TSource&amp;gt; source,&lt;br /&gt;    Func&amp;lt;TSource, TKey&amp;gt; keySelector);&lt;br /&gt;public static OrderedSequence&amp;lt;TSource&amp;gt; OrderByDescending&amp;lt;TSource, TKey&amp;gt;(&lt;br /&gt;    this IEnumerable&amp;lt;TSource&amp;gt; source,&lt;br /&gt;    Func&amp;lt;TSource, TKey&amp;gt; keySelector,&lt;br /&gt;    IComparer&amp;lt;TKey&amp;gt; comparer);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Distinct / Union - Set Operators&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;The &lt;i&gt;Distinct&lt;/i&gt; operator removes duplicate items from a given sequece. It is just the counterpart of the &lt;i&gt;Distinct&lt;/i&gt; keyword used in regular SQL statements. It has the following signature:&lt;br /&gt;&lt;br /&gt;public static IEnumerable&amp;lt;TSource&amp;gt; Distinct&amp;lt;TSource&amp;gt;(&lt;br /&gt;    this IEnumerable&amp;lt;TSource&amp;gt; source);&lt;br /&gt;public static IEnumerable&amp;lt;TSource&amp;gt; Distinct&amp;lt;TSource&amp;gt;(&lt;br /&gt;    this IEnumerable&amp;lt;TSource&amp;gt; source,&lt;br /&gt;    IEqualityComparer&amp;lt;TSource&amp;gt; comparer);&lt;br /&gt;&lt;br /&gt;In both the overloads, the source is the sequence on which the operator will operator. Using the second overload, we can specify a custom comparer to compare an element. Listing 8 shows the use of the &lt;i&gt;Distinct&lt;/i&gt; operator:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Listing 8&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;public class Fruit&lt;br /&gt;    {&lt;br /&gt;        public string name { get; set; }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;List&amp;lt;Fruit&amp;gt; fruits =&lt;br /&gt;                new List&amp;lt;Fruit&amp;gt;&lt;br /&gt;                {&lt;br /&gt;                    new Fruit { name = "Orange"},&lt;br /&gt;                    new Fruit { name = "Orange"},&lt;br /&gt;                    new Fruit { name = "Orange"},&lt;br /&gt;                    new Fruit { name = "Apple"},&lt;br /&gt;                    new Fruit { name = "Apple"},&lt;br /&gt;                    new Fruit { name = "Pappaya" }&lt;br /&gt;                };&lt;br /&gt;&lt;br /&gt;        var query =&lt;br /&gt;            (from fruit in fruits&lt;br /&gt;             select new { fruit.name}&lt;br /&gt;            ).Distinct();&lt;br /&gt;&lt;br /&gt;        foreach (var fruit in query)&lt;br /&gt;        {&lt;br /&gt;            // use fruit.name&lt;br /&gt;        }&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;The output of the above query will be following:&lt;br /&gt;&lt;br /&gt;Orange&lt;br /&gt;Apple&lt;br /&gt;Papaya&lt;br /&gt;&lt;br /&gt;Another of the Set Operators includes the &lt;i&gt;Union&lt;/i&gt; operator. A &lt;i&gt;Union&lt;/i&gt; operator returns unique elements from two sequences while ignoring the duplicates. The &lt;i&gt;Union&lt;/i&gt; operator has the following signature:&lt;br /&gt;&lt;br /&gt;public static IEnumerable&amp;lt;TSource&amp;gt; Union&amp;lt;TSource&amp;gt;(&lt;br /&gt;    this IEnumerable&amp;lt;TSource&amp;gt; first,&lt;br /&gt;    IEnumerable&amp;lt;TSource&amp;gt; second);&lt;br /&gt;public static IEnumerable&amp;lt;TSource&amp;gt; Union&amp;lt;TSource&amp;gt;(&lt;br /&gt;    this IEnumerable&amp;lt;TSource&amp;gt; first,&lt;br /&gt;    IEnumerable&amp;lt;TSource&amp;gt; second,&lt;br /&gt;    IEqualityComparer&amp;lt;TSource&amp;gt; comparer);&lt;br /&gt;&lt;br /&gt;In both the overloads, the &lt;i&gt;first&lt;/i&gt; and &lt;i&gt;second&lt;/i&gt; represents the two sequences on which the &lt;i&gt;Union&lt;/i&gt; operator is applied. The third parameter in the second overload is a custom comparer for comparison. Listing 9 shows the use of &lt;i&gt;Union&lt;/i&gt; operator:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Listing 9&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;int[] A = { 1, 2, 3, 4, 5 };&lt;br /&gt;int[] B = { 4, 5, 6, 7, 8};&lt;br /&gt;&lt;br /&gt;var union = A.Union (B);&lt;br /&gt;&lt;br /&gt;foreach (var n in union)&lt;br /&gt;{&lt;br /&gt;        // use n&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;The result of the above query will be 1, 2, 3, 4, 5, 6, 7, 8. It will ignore the duplicates 4 and 5 and yield one element each.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Summary&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;In this post, we had a look at the basic LINQ Syntax. A LINQ query is also known as a Query Expression. A query expression is a declarative way of writing query where we can perform different operations such as filtering, sorting, grouping etc. The yield of a query expression is a sequence.&lt;br /&gt;&lt;br /&gt;Another way of writing a query expression is a Method-based Query which is just a concise way of writing LINQ Query. It makes use of Lambda Expression and Extension Methods. In the background, every query expression is converted to a method-based query. However there is no performance difference between the two and it comes down to the preference of usage.&lt;br /&gt;&lt;br /&gt;A query expression makes use of Standard Query Operators. These operators represent an API defined in the System.Linq namespace. They operate on a sequence to perform different functions such as sorting, filtering, projection, grouping and much more. &lt;br /&gt;&lt;br /&gt;With this we come to an end of this post. In the next post, you will see the use of LINQ in real world applications. We will begin with LINQ-to-SQL (a provider of LINQ) which is used to query relational databases. So stay tuned for more…&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/834688215084300455-2351994357694492269?l=dotnetpost.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetpost.blogspot.com/feeds/2351994357694492269/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetpost.blogspot.com/2009/11/linq-explained-part-4.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/2351994357694492269'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/2351994357694492269'/><link rel='alternate' type='text/html' href='http://dotnetpost.blogspot.com/2009/11/linq-explained-part-4.html' title='LINQ Explained – Part 4'/><author><name>Kashif Ahmad</name><uri>http://www.blogger.com/profile/02151423871584093787</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-834688215084300455.post-4327558320394798443</id><published>2009-10-07T16:29:00.001-07:00</published><updated>2009-12-18T10:45:20.699-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='General'/><title type='text'>Back to Work...</title><content type='html'>&lt;br&gt;Hi Guys,&lt;br /&gt;&lt;br /&gt;&lt;br&gt;I have been away from my blog for some while since my schedule kept me occupied. But now I am back and will carry on writing. As a priority, I intend to complete my &lt;strong&gt;LINQ Explained&lt;/strong&gt; series. So stay tuned for more...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/834688215084300455-4327558320394798443?l=dotnetpost.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetpost.blogspot.com/feeds/4327558320394798443/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetpost.blogspot.com/2009/10/back-to-work.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/4327558320394798443'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/4327558320394798443'/><link rel='alternate' type='text/html' href='http://dotnetpost.blogspot.com/2009/10/back-to-work.html' title='Back to Work...'/><author><name>Kashif Ahmad</name><uri>http://www.blogger.com/profile/02151423871584093787</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-834688215084300455.post-3096846646391253660</id><published>2009-09-03T02:11:00.000-07:00</published><updated>2009-12-18T10:45:20.699-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='General'/><title type='text'>Some Useful Developer Tools</title><content type='html'>&lt;br&gt;&lt;br /&gt;&lt;a href="http://www.hanselman.com/blog"&gt;Scott Hanselman&lt;/a&gt; has posted some useful developer and power user tools for windows. I thought of sharing this with you. The post can be found &lt;a href="http://www.hanselman.com/blog/ScottHanselmans2009UltimateDeveloperAndPowerUsersToolListForWindows.aspx"&gt;here&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/834688215084300455-3096846646391253660?l=dotnetpost.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetpost.blogspot.com/feeds/3096846646391253660/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetpost.blogspot.com/2009/09/some-useful-developer-tools.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/3096846646391253660'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/3096846646391253660'/><link rel='alternate' type='text/html' href='http://dotnetpost.blogspot.com/2009/09/some-useful-developer-tools.html' title='Some Useful Developer Tools'/><author><name>Kashif Ahmad</name><uri>http://www.blogger.com/profile/02151423871584093787</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-834688215084300455.post-6869261355503825192</id><published>2009-08-15T05:06:00.000-07:00</published><updated>2009-08-15T05:13:24.837-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Architecture'/><title type='text'>Using Custom Entities in ASP.NET Applications – Part 3</title><content type='html'>&lt;br&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;This is the third and final part of my short series on using custom entities in asp.net applications. In this part, we will look at some coding technique commonly used to program around custom entities and data transfer objects. For the sake of brevity, I will not go into the coding details rather focus on the architectural issues. So let’s get started. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Using Custom Entities and DTOs&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;Many of the sample applications show how to use Custom Entities (and DTOs). In addition to the standard UI, BLL and DAL Layer, &lt;i&gt;the usual design is to have a fourth layer (usually known as Model Layer) consisting of Data Transfer Objects&lt;/i&gt;. The DTOs in the model layer is used for transfer of data betweent the three layers. Usually when a user makes a request, it flows from the UI to the BLL and finally to the DAL. In response, the DAL populates one or more DTOs and sends it back to the BLL. &lt;b&gt;&lt;i&gt;The BLL then sends the data back to the UI&lt;/i&gt;&lt;/b&gt;. Pay close attention to this last statement which is highlighted. To me, this is where we can employ different coding techniques and this decision is left to the developer. Let me explain these techniques in the following sections with examples. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Using DTOs - Only&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;&lt;i&gt;In this technique, only DTOs are used between all the layers for transfer of data&lt;/i&gt;. The BLL returns the same DTOs received from the DAL to the UI. The UI binds to one or more instances of DTOs. Listing 1 shows this technique:&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Listing 1&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;// Model Layer&lt;br /&gt;using System;&lt;br /&gt;&lt;br /&gt;public class EmployeeDTO&lt;br /&gt;{&lt;br /&gt;    // properties&lt;br /&gt;    public int      EmployeeID    { get; set; }&lt;br /&gt;    public string   Name          { get; set; }&lt;br /&gt;    public string   Address       { get; set; }&lt;br /&gt;    public string   Designation   { get; set; }&lt;br /&gt;    public int      Age           { get; set; }&lt;br /&gt;&lt;br /&gt;    // constructor&lt;br /&gt; public EmployeeDTO () {}&lt;br /&gt;&lt;br /&gt;    // constructor&lt;br /&gt;    public EmployeeDTO (int employeeId, string name, string address, string designation, int age)&lt;br /&gt;    {&lt;br /&gt;        this.EmployeeID     = employeeId;&lt;br /&gt;        this.Name           = name;&lt;br /&gt;        this.Address        = address;&lt;br /&gt;        this.Designation    = designation;&lt;br /&gt;        this.Age            = age;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;// Business Logic Layer&lt;br /&gt;using System;&lt;br /&gt;&lt;br /&gt;public class Employee&lt;br /&gt;{&lt;br /&gt;    public Employee () {}&lt;br /&gt;&lt;br /&gt;    public IList &lt;EmployeeDTO&gt; GetAllEmployees ()&lt;br /&gt;    {&lt;br /&gt;        return EmployeeDAL.GetAllEmployees ();&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public EmployeeDTO GetEmployeeById (int employeeId)&lt;br /&gt;    {&lt;br /&gt;        return EmployeeDAL.GetEmployeeById (employeeId);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public int Save (EmployeeDTO employee)&lt;br /&gt;    {&lt;br /&gt;        return EmployeeDAL.Save (employee);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    // Validation…&lt;br /&gt;&lt;br /&gt;   // Business Rules…&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;The &lt;i&gt;Emloyee&lt;/i&gt; entity in the BLL has a corresponding data transfer object (EmployeeDTO) in the Model Layer. The Employee entity has different CRUD methods. These methods accept and return one or more instances of type EmployeeDTO. This technique is shown in figure 1.&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;DTO&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;DTO&lt;br /&gt;UI &lt;----------&gt; BLL &lt;-----------&gt; DAL&lt;br /&gt;&lt;b&gt;Fig 1&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;There is nothing wrong in using DTOs throughout the application. But to me, this has a few shortcomings. First of all, this technique breaks the basic principle of OO programming, &lt;i&gt;Encapsulation&lt;/i&gt;. Encapsulation states that both the state and behavior are held within the object. The object itself is responsible for managing its state and behavior. The state or behavior cannot be separated from the object. In the above code, the Employee class (residing in the BLL) does not define any state. It instead relies on the EmployeeDTO (Model Layer) to handle its state. This shows that the object is not in charge of its state and hence clearly breaks the principle of encapsulation.&lt;br /&gt;&lt;br /&gt;Second, custom entities (defined in the BLL) have association with each other. These associations are defined by the help of their properties (primary keys). If they lack any property (as in the above code) then how do we define an association? I don’t see a point in defining associations in the Model Layer between data transfer objects (which lack any behavior as well).&lt;br /&gt;&lt;br /&gt;Data Transfer Objects lack behavior yet they are not without advantage. Since they only consist of properties, they are light weight objects used to send data across subsystems and hence help improve the throughput of the system. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Using DTOs in parallel to Custom Entities&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;In this case, &lt;i&gt;DTOs are limited between the BLL and DAL for transfer of data&lt;/i&gt;. However; the UI binds to custom entities instead of DTOs. This is possible since the custom entities define both the state and behavior. Before the UI binds to a custom entity, the custom entity copies over the properties of the DTO. This way, the data is available when the UI binds to a custom entity. Let us see this approach in listing 2:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Listing 2&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;// Model Layer&lt;br /&gt;using System;&lt;br /&gt;&lt;br /&gt;public class EmployeeDTO&lt;br /&gt;{&lt;br /&gt;    // properties&lt;br /&gt;    public int      EmployeeID    { get; set; }&lt;br /&gt;    public string   Name          { get; set; }&lt;br /&gt;    public string   Address       { get; set; }&lt;br /&gt;    public string   Designation   { get; set; }&lt;br /&gt;    public int      Age           { get; set; }&lt;br /&gt;&lt;br /&gt;    // constructor&lt;br /&gt; public EmployeeDTO () {}&lt;br /&gt;&lt;br /&gt;    // constructor&lt;br /&gt;    public EmployeeDTO (int employeeId, string name, string address, string designation, int age)&lt;br /&gt;    {&lt;br /&gt;        this.EmployeeID     = employeeId;&lt;br /&gt;        this.Name           = name;&lt;br /&gt;        this.Address        = address;&lt;br /&gt;        this.Designation    = designation;&lt;br /&gt;        this.Age            = age;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// Business Logic Layer&lt;br /&gt;using System;&lt;br /&gt;&lt;br /&gt;public class Employee&lt;br /&gt;{&lt;br /&gt;    // properties&lt;br /&gt;    public int      EmployeeID  { get; set; }&lt;br /&gt;    public string   Name        { get; set; }&lt;br /&gt;    public string   Address     { get; set; }&lt;br /&gt;    public string   Designation { get; set; }&lt;br /&gt;    public int      Age         { get; set; }&lt;br /&gt;&lt;br /&gt;    // constructor&lt;br /&gt;    public Employee() {}&lt;br /&gt;&lt;br /&gt;    // constructor&lt;br /&gt;    public Employee (int employeeId, string name, string address, string designation, int age)&lt;br /&gt;    {&lt;br /&gt;        this.EmployeeID     = employeeId;&lt;br /&gt;        this.Name           = name;&lt;br /&gt;        this.Address        = address;&lt;br /&gt;        this.Designation    = designation;&lt;br /&gt;        this.Age            = age;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    // ------------------- CRUD Methods -------------------------------&lt;br /&gt;    public IList &lt;Employee&gt; GetAllEmployees ()&lt;br /&gt;    {&lt;br /&gt;        return ConvertListOfEmployees (EmployeeDAL.GetAllEmployees ()); // convert to list of BO before sending to UI&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public EmployeeDTO GetEmployeeById (int employeeId)&lt;br /&gt;    {&lt;br /&gt;        return MapToBO (EmployeeDAL.GetEmployeeById (employeeId)); // convert to BO before sending to UI&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public int Save (Employee employee)&lt;br /&gt;    {&lt;br /&gt;        return EmployeeDAL.Save (MapToDTO (employee)); // convert to DTO before sending to UI&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;br /&gt;    // ------------------- Converters ---------------------------------&lt;br /&gt;    // Convert list of EmployeeDTO to list of Employee&lt;br /&gt;    private void ConvertListOfEmployee (IList &lt;EmployeeDTO&gt; employeeList)&lt;br /&gt;    {&lt;br /&gt;        IList &lt;EmployeeDTO&gt; EmployeeCollection;&lt;br /&gt;&lt;br /&gt;        foreach (EmployeeDTO employee in employeeList)&lt;br /&gt;        {&lt;br /&gt;            EmployeeCollection.Add (MapToBO (employee));&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        return EmployeeCollection;&lt;br /&gt;    }    &lt;br /&gt;&lt;br /&gt;    // Convert an EmployeeDTO to Employee&lt;br /&gt;    private Employee MapToBO (EmployeeDTO employee)&lt;br /&gt;    {&lt;br /&gt;        return new Employee (employee.EmployeeID, Name, Age, Address, Designation);&lt;br /&gt;    }    &lt;br /&gt;&lt;br /&gt;    // Convert an Employee to EmployeeDTO&lt;br /&gt;    private Employee MapToDTO (Employee employee)&lt;br /&gt;    {&lt;br /&gt;        return new EmployeeDTO (employee.EmployeeID, Name, Age, Address, Designation);&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;As you can see clearly, the above Employee Entity follows the principle of encapsulation. &lt;i&gt;Both the state and behavior are encapsulated within the entity&lt;/i&gt;. However, in addition to the CRUD methods, the entity has a set of converters which are used to convert a DTO to a CE and vice versa. In my view, this is the only shortcoming of using this approach which may incur some overhead. But this overhead is minimal and can be ignored easily. &lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CE&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;DTO&lt;br /&gt;UI &lt;----------&gt; BLL &lt;-----------&gt; DAL&lt;br /&gt;&lt;b&gt;Fig 2&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Why not use Custom Entities directly&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;Curios readers must be thinking “Why not just use custom entities throughout the layers” i.e. In addition to the UI, custom entities can be referenced by DAL as well. This way we don’t need to have an extra layer of data transfer objects. The answer to this is that referencing custom throughout will create a circular reference between the BLL and DAL. A reference to the DAL from the BLL is unidirectional. But if DAL also references the BLL, it results in a bidirectional reference which leads to a circular reference. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Summary&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;In this part, we saw how to use custom entities in conjunction with data transfer objects. We looked at two different techniques. The first technique uses DTOs for transfer of data through all the layers. This technique works well but does not follow the principle of encapsulation. Also, this leads to the confusion as what is the best place to define the association. Should we define it at the BLL layer or the Model layer?&lt;br /&gt;&lt;br /&gt;The second technique uses DTOs only between the BLL and DAL. The UI communicates with the BLL through the custom entities. This approach removes both the problems the first approach, however; it incurs a slight overhead of converting custom entities to DTOs and vice versa. &lt;br /&gt;&lt;br /&gt;With this, we come to the end of this series. But this is just not it. I plan to write more on custom entities as this has become the standard coding practice. Please do provide your feedback through your comments. Stay tuned for more... &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/834688215084300455-6869261355503825192?l=dotnetpost.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetpost.blogspot.com/feeds/6869261355503825192/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetpost.blogspot.com/2009/08/using-custom-entities-in-aspnet_15.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/6869261355503825192'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/6869261355503825192'/><link rel='alternate' type='text/html' href='http://dotnetpost.blogspot.com/2009/08/using-custom-entities-in-aspnet_15.html' title='Using Custom Entities in ASP.NET Applications – Part 3'/><author><name>Kashif Ahmad</name><uri>http://www.blogger.com/profile/02151423871584093787</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-834688215084300455.post-7416187498631266232</id><published>2009-08-10T09:14:00.000-07:00</published><updated>2009-08-10T09:15:50.779-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Architecture'/><title type='text'>Using Custom Entities in ASP.NET Applications – Part 2</title><content type='html'>&lt;br&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;This is the second part of my short series on using Custom Entities in asp.net applications. In this part we will see how association between custom entities is defined. We will also explore the different types of association between which can exist between custom entities. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Association between Entities &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;In the database world, relationship is a mandatory feature. Different tables are linked to each other through relationships. Relationships are defined by the help of primary keys. These primary keys are placed as reference (foreign keys) in other tables. &lt;i&gt;In OO programming, this relationship between entities (or classes) is known as &lt;b&gt;association&lt;/b&gt;. Each custom entity is uniquely identified by an &lt;b&gt;entity identity or identifier&lt;/b&gt;&lt;/i&gt;. This &lt;i&gt;entity identity maps to the primary key in the database&lt;/i&gt;. &lt;br /&gt;&lt;br /&gt;In custom entities, an association is defined by placing the identity of one entity in the other. For example lets assume two entities &lt;i&gt;Book&lt;/i&gt; and &lt;i&gt;Author&lt;/i&gt;. Since a book always has an author (not to mention how many) we can define this association by placing the author identity in the book entity as show in listing 1:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Listing 1&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;public class Book &lt;br /&gt;{&lt;br /&gt;          private int bookID;&lt;br /&gt;          private string title;&lt;br /&gt;          // other properties&lt;br /&gt;&lt;br /&gt;          private int AuthorID; // association&lt;br /&gt;&lt;br /&gt;          // other constructs&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Association between Entities &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;In the following sections, we will look at the different types of association, also known as &lt;b&gt;&lt;i&gt;cardinality&lt;/i&gt;&lt;/b&gt; between entities.  For this purpose, I will use the following entities:&lt;br /&gt;&lt;br /&gt;• Customer&lt;br /&gt;• Orders&lt;br /&gt;• Products&lt;br /&gt;• Suppliers&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;One-to-Many Association&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;In this type of association, one instance of an entity type is associated with multiple instances of the second type. For example, one Customer can have many Orders. In this case, &lt;i&gt;the Customer is the owner of this association&lt;/i&gt;. So the Customer entity &lt;i&gt;specifies the mapping by having a child list object of type Order&lt;/i&gt; as shown in listing 3:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Listing 3&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;public class Customer&lt;br /&gt;{&lt;br /&gt;          private int CustomerID;&lt;br /&gt;          // other properties&lt;br /&gt;&lt;br /&gt;          private IList&lt;Orders&gt; OrderCollection; // 1:M association&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Many-to-One Association&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;In this type of association, multiple instances of one entity type are associated with a single instance of another type. For example, many Orders (owner) belong to one Customer. So each Order specifies the mapping by including the identity of the related Customer as shown in listing 4:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Listing 4&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;public class Order&lt;br /&gt;{&lt;br /&gt;          private int OrderID;&lt;br /&gt;          // other properties&lt;br /&gt;&lt;br /&gt;          private int CustomerID; // M:1 association&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Many-to-Many Association&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;In a many to many association, multiple instances of one entity type are associated with multiple instances of the other type. For example, many Products have many Suppliers and vice versa. In this case, both entities are the owner and have a child list collection of the related entity as shown in listing 5:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Listing 5&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;public class Product&lt;br /&gt;{&lt;br /&gt;          private int ProductID;&lt;br /&gt;          // other properties&lt;br /&gt;&lt;br /&gt;          private IList&lt;Supplier&gt; SupplierCollection; // M:M association&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public class Supplier&lt;br /&gt;{&lt;br /&gt;          private int SupplierID;&lt;br /&gt;          // other properties&lt;br /&gt;&lt;br /&gt;          private IList&lt;Product&gt; ProductCollection; // M:M association&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;One-to-One Association&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;One to One association is not very common and exists in special cases. For example, if a database table is very large and most of the fields are rarely used then the database designer tends to separate out these fields in a different table to improve performance. But both the tables are still linked through the same identity. In custom entities, such association is presented by a single entity which has all the fields. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Using an Identifier or a Full-Blown Object&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;One question commonly asked on different forums is that when defining an association, should we use the &lt;i&gt;entity identity (&lt;b&gt;a primitive data type&lt;/b&gt;)&lt;/i&gt; or a &lt;i&gt;full blown object&lt;/i&gt; of the entity being referenced. In other words, listing 1 can be rewritten as following:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Listing 6&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;public class Book &lt;br /&gt;{&lt;br /&gt;          private int bookID;&lt;br /&gt;          private string title;&lt;br /&gt;          // other properties&lt;br /&gt;&lt;br /&gt;          private Author author; // association – Full Blown Object&lt;br /&gt;&lt;br /&gt;          // other constructs&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;Watch closely, in the above listing, we are not using the simple AuthorID of type integer to define the mapping. Rather we have used a child object of type ‘Author’. This is one approach taken by developers. To me, the answer to the above question depends on different factors including the technology being used plus the user requirements. Let me explain both these scenarios in details. &lt;br /&gt;&lt;br /&gt;First, ASP.NET comes with many built in controls which make data binding a breeze. These controls including the ObjectDataSource, GridView, ListView etc &lt;i&gt; are capable of binding to custom entities&lt;/i&gt; as well. However, these controls can only bind to properties of primitive types (int, string, bit etc). &lt;i&gt;These controls cannot bind to complex child object or collection&lt;/i&gt;. To me, this is a short coming in the framework and hopefully will be removed in a future version. Although there are workaround, but they do not offer a concrete solution. So if the custom entity contains a reference of simple type, it can easily bind to a data control.&lt;br /&gt;&lt;br /&gt;Second, the user requirement also plays an important role. Suppose we are creating an application for a retail outlet. A &lt;i&gt;Customer&lt;/i&gt; makes an &lt;i&gt;Order&lt;/i&gt; for different purchases. This customer may already exist in the system. Now if we have modeled our Order class to have a full blown Custom child object, we can easily create both the Order and the Customer object. Why because we have full access to the Customer object through the Order object. This way when the Order is passed down to the DAL, the entire Customer object is passed along and saved to the database. On the other hand, if the Order only had a reference to Customer identity, we first had to create a new Customer and then assign his identity to the Order object. This would be more like a two step process.&lt;br /&gt;&lt;br /&gt;In the end, to me it remains a user preference whether to use a reference of simple or custom type. Different factors play in and have to be considered before preference is locked down. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Light-Weight Model and Association&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;When it comes to architecture, different people have different opinions (and they are justified as well). When defining association between entities, it tends to get very complex and difficult to handle. Custom Entities may have a deep hierarchy of association. For example, a Product is composed of Components. Each Component has many Parts and each Part may be made up of Sub-Parts. With such hierarchy, many issues have to be considered. For example, if we make changes at any level or the hierarchy, the entire hierarchy has to be persisted. Similarly, if we are making changes at any level and the parent hierarchy leaves the transaction, all the properties have to be restored back to the original state. There are numerous scenarios with such deep hierarchy.&lt;br /&gt;&lt;br /&gt;An alternative to deal with such associations is by defining a light-weight model. This means that there is no need to have a child object with the parent object. We can instead use method (or more specifically services) to fetch the child data. This is more like a Service-Oriented Architecture where we tend to rely on services. The concept is to simply fetch the data when required.&lt;br /&gt;&lt;br /&gt;For example, using the above approach, we can rewrite listing 1 as following:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Listing 7&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;public class Book &lt;br /&gt;{&lt;br /&gt;          private int bookID;&lt;br /&gt;          private string title;&lt;br /&gt;          // other properties&lt;br /&gt;&lt;br /&gt;          public Author GetBookAuthor ()&lt;br /&gt;          {&lt;br /&gt;                    //return GetBookAuthor (this.bookID)&lt;br /&gt;          }&lt;br /&gt;&lt;br /&gt;          // other constructs&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;In the above listing, an Author object is returned using the method GetBookAuthor. This eliminates the need to reference the Author object within the Book class. I am sure you can see the advantages of using this approach. However, my opinion is not final. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Summary&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;In this post, we saw the how association is defined between entities. We also looked at the different types of associations also known as ‘cardinality’. We also looked at the different scenarios which lead to deciding whether to use a reference of primitive type or a full blown object. In the next post, we will see how to code around custom entities. Stay tuned for more…&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/834688215084300455-7416187498631266232?l=dotnetpost.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetpost.blogspot.com/feeds/7416187498631266232/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetpost.blogspot.com/2009/08/using-custom-entities-in-aspnet_10.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/7416187498631266232'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/7416187498631266232'/><link rel='alternate' type='text/html' href='http://dotnetpost.blogspot.com/2009/08/using-custom-entities-in-aspnet_10.html' title='Using Custom Entities in ASP.NET Applications – Part 2'/><author><name>Kashif Ahmad</name><uri>http://www.blogger.com/profile/02151423871584093787</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-834688215084300455.post-1011226232510907662</id><published>2009-08-07T00:39:00.000-07:00</published><updated>2009-08-10T09:16:48.319-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Architecture'/><title type='text'>Using Custom Entities in ASP.NET Applications – Part 1</title><content type='html'>&lt;br&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;Recently there has been a surge of architecture-related discussion in the .NET community. This stems from the fact that business applications are getting complex and intricate to build. Building N-Tier business applications is both a requirement and a challenging task. This cannot be achieved by just using a specific framework such as the .NET Framework. The .NET Framework does provide a rich library for building enterprise business applications but this is half the story. Sound Object-Oriented principles supported by architectural patterns apply across all development platforms without targeting a specific technolgy. This combination of technology, OO principle and architecture results in applications which are scalable, fault tolerant and user interactive.&lt;br /&gt;&lt;br /&gt;In this short series, I will talk about using Business Entities in ASP.NET applications. The reason behind this series to present my two cents on most of the question asked on the forums regarding developing N-Tier applications using Custom Entities. This discussion is not intended to explain OO programming. The focus is to discuss architecture issues when using Custom Entities. I will start with simple concepts and then extend it from there.&lt;/span&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;What’s wrong with DataSet&lt;/span&gt; &lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;Honestly speaking, DataSets are not evil at all and I prefer to use them whenever I can. It’s easy to program around a DataSet and IMHO, works great for small to mid sized applications. If you really fine tune the data layer accessing the database, a DataSet gives optimal performance. In addition to this, many of the data controls available in asp.net including ObjectDataSource, GridView, Datalist etc work really well with DataSets. However, a DataSet has its limitations and is not suited for every situation especially when used for Enterprise Applications. The most commonly faced problems include:&lt;br /&gt;&lt;br /&gt;• They are not strongly-typed&lt;br /&gt;• They lack validation and business rules.&lt;br /&gt;• They do not support OO principles such as Encapsulation, Inheritance etc&lt;br /&gt;• DataSet have a performance issue when used for large amount of data (&lt;a href="http://msdn.microsoft.com/en-us/magazine/cc163751.aspx"&gt;see this&lt;/a&gt;)&lt;br /&gt;• DataSets are not interoperable with applications written in other languages such as Java, PHP etc&lt;br /&gt;• The use of DataSet dictates the Data-First design whereas OO principles focuses on Domain-First design&lt;br /&gt;• Maintenance becomes difficult when an application starts growing with time (which every application does) &lt;br /&gt;&lt;br /&gt;The alternative is to use custom entities discussed in the following section. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Using Custom Entities&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;Seasoned programmers tend to use classes for developing business applications. Classes allow the developers to take advantage of a rich OO programming model. This model comes with a set of well defined OO principles including Data Abstraction, Information Hiding, Encapsulation, Inheritance etc.&lt;br /&gt;&lt;br /&gt;In its essence, a custom entity is just a regular class. But what makes it different is that it is a domain object. In business applications, domain objects identify the key entities within the system. Each domain object can be represented by a Custom Entity. &lt;br /&gt;&lt;br /&gt;In addition to supporting OO principles, a custom entity defines business rules and custom validation. This subtle addition is the real difference between a regular class and a custom entity. For example, let’s look at the following &lt;b&gt;Book&lt;/b&gt; custom entity: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;public class Book&lt;br /&gt;{&lt;br /&gt;          // properties&lt;br /&gt;          public int BookId { get; set; }&lt;br /&gt;          public string ISBN { get; set; }&lt;br /&gt;          public string Title { get; set; }&lt;br /&gt;          public string Author { get; set; }&lt;br /&gt;&lt;br /&gt;          // constructors&lt;br /&gt;          public Book () {}&lt;br /&gt;&lt;br /&gt;          public Book (string isbn, string title, string author)&lt;br /&gt;          {&lt;br /&gt;                    // set values&lt;br /&gt;          }&lt;br /&gt;&lt;br /&gt;          // simple method&lt;br /&gt;          public int BuyBook (string ISBN)&lt;br /&gt;          {&lt;br /&gt;                    // process&lt;br /&gt;          }&lt;br /&gt;          &lt;br /&gt;          // validation rule&lt;br /&gt;          public book Validate (Book book)&lt;br /&gt;          {&lt;br /&gt;                    if (book.ISBN == null)&lt;br /&gt;                              return false;&lt;br /&gt;                    // other rules&lt;br /&gt;          }&lt;br /&gt;&lt;br /&gt;          // business rule&lt;br /&gt;          public int isPremiumMember (int customerId)&lt;br /&gt;          {&lt;br /&gt;                    // if customer is a premium member &lt;br /&gt;                    //     eligible for gift voucher&lt;br /&gt;                    //     return voucherNumber&lt;br /&gt;          }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;The above entity defines the normal properties, constructors and a method (BuyBook). In addition to these constructs, the class also defines a validation method (Validate) and a business rule (isPremiumMember). The Validate method validates the state of the object while isPremiumMember method determines if the customer is eligible for a gift voucher given he is a premium member. This is just a trivial example. True custom entities can have a complex set of business rules.&lt;br /&gt;&lt;br /&gt;Different terms including &lt;b&gt;Business Object, Business Entity and Custom Business Entity&lt;/b&gt; are used interchangeably to represent a Custom entity. Though the purists may differentiate between them but IMHO, they all are the same. It’s just a preference of term used by different users. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Data Transfer Objects &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;&lt;i&gt;Data Transfer Object (DTO)&lt;/i&gt; is a design pattern used to transfer data between software application subsystems. It is basically a data container. The main difference between a DTO and a Custom Entity is that a DTO does not have any behavior or responsibility and only consists of properties. A DTO is also known as a dumb object due to the lack of any behavior. Using a DTO has several advantages including:&lt;br /&gt;&lt;br /&gt;• All data is summed up in one DTO and passed down to a layer&lt;br /&gt;• Since an entire object is passed down the wire, adding or removing properties to the object does not effect the calls&lt;br /&gt;• DTOs are light weight objects which give better as compared to DataSets&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Keeping above in mind, the &lt;i&gt;book BO&lt;/i&gt; in the above section can have the following corresponding Book DTO:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;public class BookDTO&lt;br /&gt;{&lt;br /&gt;          public int BookId { get; set; }&lt;br /&gt;          public string ISBN { get; set; }&lt;br /&gt;          public string Title { get; set; }&lt;br /&gt;          public string Author { get; set; }&lt;br /&gt;&lt;br /&gt;          public Book () {}&lt;br /&gt;&lt;br /&gt;          public Book (string isbn, string title, string author)&lt;br /&gt;          {&lt;br /&gt;                    // set values&lt;br /&gt;          }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Using Custom Entities and DTOs&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;A typical 3-tier (logical) application has three layers namely User Interface Layer (UI), Business Logic Layer (BLL) and the Data Access Layer (DAL). The UI layer provides an interface to the user to interact with the system. The BLL (application layer, middle layer) is where all the business logic resides and the DAL deals with operations of the data source. The UI never interacts with the DAL directly. When a user makes a request from the UI, the request is directed to the BLL. The BLL then forwards the request to the DAL. The typical flow of a user request is as following:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;UI &lt;-&gt; BLL &lt;-&gt; DAL&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;The question is how the data transfers between the layers? This is where the DTOs come into play. When the user request reaches the DAL, the DAL fetches the data from the data source and bundles it into a DTO. The DTO is then returned to the BLL followed by the UI. Similarly when a user creates or updates a record, the entire DTO is transferred back to the BLL and then to the DAL.&lt;br /&gt;The update and delete process can be handled by just using the primary key value. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Is a DTO a Custom Entity&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;This is an interesting question. I have seen many applications where both the terms are used interchangeably. There is no harm in doing so but I tend to disagree. A DTO is really a design pattern used to transfer data between subsystems. Although it a class but keep in mind that a DTO does not define any behavior, business rules, validation or relationship. In the following posts, I will show you how a DTO is used both as a custom entity and individually.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Summary &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;In this post, I just gave you an overview of what Custom entities are and  tried to understand the basics of using Custom Entities when developing business applications. In the following post, we will dive deeper and explore more about custom entities. &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/834688215084300455-1011226232510907662?l=dotnetpost.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetpost.blogspot.com/feeds/1011226232510907662/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetpost.blogspot.com/2009/08/using-custom-entities-in-aspnet.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/1011226232510907662'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/1011226232510907662'/><link rel='alternate' type='text/html' href='http://dotnetpost.blogspot.com/2009/08/using-custom-entities-in-aspnet.html' title='Using Custom Entities in ASP.NET Applications – Part 1'/><author><name>Kashif Ahmad</name><uri>http://www.blogger.com/profile/02151423871584093787</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-834688215084300455.post-7873409244091939861</id><published>2009-07-09T13:19:00.000-07:00</published><updated>2009-07-09T13:34:07.206-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WCF'/><title type='text'>Getting Started with WCF Service</title><content type='html'>&lt;span style="font-family:Verdana;"&gt;In this post, I will walk you through creating your first Windows Communication Foundation Service. Those new to WCF should read my &lt;a href="http://dotnetpost.blogspot.com/2009/06/fundamentals-of-windows-communication.html"&gt;previous&lt;/a&gt; post to understand the basics concepts of WCF Service. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Introduction&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;Before a WCF Service can be consumed by a client application, the following three steps are required:&lt;br /&gt;&lt;br /&gt;Service: The actual WCF Service which provides business functionality&lt;br /&gt;Host: A hosting environment which hosts the service&lt;br /&gt;Client: A client application/service which invokes the WCF Service&lt;br /&gt;&lt;br /&gt;In the following sections, we will create a solution which consists of three separate projects representing the service, host and the client respectively. I will be using Visual Studio 2008 to create the application. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Getting Started&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;&lt;br /&gt;1. Start a new instance of Visual Studio 2008.&lt;br /&gt;2. Click on File -&gt; New Project. From &lt;i&gt;Project types&lt;/i&gt; pane, select &lt;i&gt;Visual Studio Solutions&lt;/i&gt;&lt;br /&gt;3. From the &lt;i&gt;Template&lt;/i&gt; pane, select &lt;i&gt;Blank Solution&lt;/i&gt;&lt;br /&gt;4. Enter &lt;b&gt;WCFIntroduction&lt;/b&gt; for Project Name. Also specify the location according to you working preference&lt;br /&gt;&lt;br /&gt;This will create a blank solution as shown in figure 1. Let us now create the actual WCF Service.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_a0lOQELDZCg/SlZRZ3pGzaI/AAAAAAAAAC0/3gJg18CZR5s/s1600-h/1.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 400px; height: 297px;" src="http://2.bp.blogspot.com/_a0lOQELDZCg/SlZRZ3pGzaI/AAAAAAAAAC0/3gJg18CZR5s/s400/1.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5356558311678725538" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;b&gt;Fig 1&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Creating the Service&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;&lt;br /&gt;1. In the solution explorer, right click on ‘WCFIntroduction’ and select Add -&gt; New Project.&lt;br /&gt;2. Select Class Library template and name it as &lt;b&gt;WCFCalculator&lt;/b&gt;. Make sure that the location is set to ..\WCFIntroduction as shown in figure 2. Click OK to create the project.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_a0lOQELDZCg/SlZRmQQozbI/AAAAAAAAAC8/R7OC0EDJgdw/s1600-h/2.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 400px; height: 262px;" src="http://2.bp.blogspot.com/_a0lOQELDZCg/SlZRmQQozbI/AAAAAAAAAC8/R7OC0EDJgdw/s400/2.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5356558524445412786" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;b&gt;Fig 2&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;&lt;br /&gt;3. The newly created project contains a single file ‘Class1.cs’. Rename it to ‘WCFCalculatorService.cs’. We will return to this file shortly.&lt;br /&gt;4. From the solution explorer, right click on ‘WCFCalculator’ project and select ‘Add Reference’. The ‘Add Reference’ dialog appears. From the .NET tab, select ‘System.ServiceModel’ and click OK. A reference to the respective namespace is added which is required to work with WCF Services&lt;br /&gt;5. Again right click on ‘WCFCalculator’ project and select Add -&gt; New Item. Select ‘Class’ template, name it as ‘IWCFCalculatorService.cs’ as shown in figure 3 and click Add&lt;br /&gt;6. This will create a new class file ready to be coded&lt;br /&gt;&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_a0lOQELDZCg/SlZRzJZ3EWI/AAAAAAAAADE/jn1UopAAdRE/s1600-h/3.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 400px; height: 247px;" src="http://4.bp.blogspot.com/_a0lOQELDZCg/SlZRzJZ3EWI/AAAAAAAAADE/jn1UopAAdRE/s400/3.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5356558745943347554" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;b&gt;Fig 3&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;&lt;br /&gt;7. Change the class definition to ‘public interface IWCFCalculatorService’. Type in the code as shown in listing 1 and save the file&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Listing 1&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.ServiceModel;&lt;br /&gt;&lt;br /&gt;namespace WCFCalculator&lt;br /&gt;{&lt;br /&gt;    [ServiceContract(Namespace = "http://youruniquedomain")]&lt;br /&gt;    public interface IWCFCalculatorService&lt;br /&gt;    {&lt;br /&gt;        [OperationContract]&lt;br /&gt;        int AddNumbers (int x, int y);&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;&lt;br /&gt;8. Let us now return to the ‘WCFCalculatorService.cs’ file. Open it and type in the following code:&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Listing 2&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.ServiceModel;&lt;br /&gt;&lt;br /&gt;namespace WCFCalculator&lt;br /&gt;{&lt;br /&gt;    public class WCFCalculatorService : IWCFCalculatorService&lt;br /&gt;    {&lt;br /&gt;        public int AddNumbers (int x, int y)&lt;br /&gt;        {&lt;br /&gt;            return x + y;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;&lt;br /&gt;Compile this project to make sure there are no errors. We have just created a very basic WCF Service used to add two numbers. The next step is to host this service in a hosting environment. In the following section, we will create a windows console application which will host this service. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Hosting the Service&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;&lt;br /&gt;1. Right click on the solution ‘WCFIntroduction’ and select Add -&gt; New Project.&lt;br /&gt;2. Select ‘Console Application’ template, name it as ‘Host’ as shown in figure 4 and click OK&lt;br /&gt;&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_a0lOQELDZCg/SlZR9r7AKOI/AAAAAAAAADM/chrtFShLdLk/s1600-h/4.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 400px; height: 262px;" src="http://3.bp.blogspot.com/_a0lOQELDZCg/SlZR9r7AKOI/AAAAAAAAADM/chrtFShLdLk/s400/4.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5356558927007852770" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;b&gt;Fig 4&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;3. Right click on ‘Host’ project and select Add Reference. From the .NET tab, select System.ServiceModel. From the Projects tab, select ‘WCFCalculator’ and press OK&lt;br /&gt;4. The Host project consists of one file ‘Program.cs’. Open this file and type in the code as shown in listing 3&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Listing 3&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.ServiceModel;&lt;br /&gt;&lt;br /&gt;namespace Host&lt;br /&gt;{&lt;br /&gt;    class Program&lt;br /&gt;    {&lt;br /&gt;        static void Main (string[] args)&lt;br /&gt;        {&lt;br /&gt;            using (ServiceHost host = new ServiceHost (typeof (WCFCalculator.WCFCalculatorService), new Uri ("http://localhost:8000/WCFCalculator")))&lt;br /&gt;            {&lt;br /&gt;                host.AddServiceEndpoint (typeof (WCFCalculator.IWCFCalculatorService), new BasicHttpBinding (), "WCFCalculatorService");&lt;br /&gt;                host.Open ();&lt;br /&gt;&lt;br /&gt;                Console.WriteLine ("Press &lt;ENTER&gt; to terminate service...");&lt;br /&gt;                Console.ReadLine ();           &lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;&lt;br /&gt;5. Compile this project. Make sure that the Host project is set as Startup Project (You can do so by right clicking on Host project and select ‘Set as Startup Project’). Press Ctrl+F5 to run this project. You should see a command window with message ‘Press &lt;ENTER&gt; to terminate service...’ as shown in figure 5. This means the service is up and runninig. Keep this window open (service is active). Next we will create a client application which will interact with this service. Let us return to our solution.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_a0lOQELDZCg/SlZSKgEfzZI/AAAAAAAAADU/0JDVg3ORNSs/s1600-h/5.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 400px; height: 87px;" src="http://2.bp.blogspot.com/_a0lOQELDZCg/SlZSKgEfzZI/AAAAAAAAADU/0JDVg3ORNSs/s400/5.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5356559147164749202" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;b&gt;Fig 5&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Consuming the Service – Client Application&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;&lt;br /&gt;1. Right click on solution ‘WCFIntroduction’ and select Add -&gt; New Project&lt;br /&gt;2. Select ‘Console Application’ template, name it as Client and click OK as shown in figure 6&lt;br /&gt;&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_a0lOQELDZCg/SlZSXf2nLbI/AAAAAAAAADc/29NC18yE5ms/s1600-h/6.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 400px; height: 262px;" src="http://1.bp.blogspot.com/_a0lOQELDZCg/SlZSXf2nLbI/AAAAAAAAADc/29NC18yE5ms/s400/6.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5356559370444811698" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;b&gt;Fig 6&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;3. Add a reference to System.ServiceModel namespace (as done in the above steps)&lt;br /&gt;4. This project consists of a single file ‘Program.cs’. Open this file and type in the code as shown in listing 4&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Listing 4&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.ServiceModel;&lt;br /&gt;&lt;br /&gt;namespace Client&lt;br /&gt;{&lt;br /&gt;    class Program&lt;br /&gt;    {&lt;br /&gt;        static void Main (string[] args)&lt;br /&gt;        {&lt;br /&gt;            EndpointAddress         endPoint;&lt;br /&gt;            IWCFCalculatorService   proxy;&lt;br /&gt;            int                     result;&lt;br /&gt;&lt;br /&gt;            endPoint = new EndpointAddress ("http://localhost:8000/WCFCalculator/WCFCalculatorService");&lt;br /&gt;            proxy    = ChannelFactory&lt;IWCFCalculatorService&gt;.CreateChannel (new BasicHttpBinding (), endPoint);&lt;br /&gt;            result = proxy.AddNumbers (2, 3);&lt;br /&gt;            &lt;br /&gt;            Console.WriteLine ("2 + 3 = " + result.ToString ());&lt;br /&gt;            Console.WriteLine ("Press &lt;ENTER&gt; to terminate client...");&lt;br /&gt;            Console.ReadLine ();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;&lt;br /&gt;5. &lt;b&gt;Here is the tricky part&lt;/b&gt;. In the above code, a proxy is created using the Service Contract (IWCFCalculatorService). To use this interface, copy it over from the ‘WCFCalculator’ project to the ‘Client’ project. Don’t forget to change the namespace to ‘Client’ in this file (In short the same interface now exists in both the ‘WCFCalculator’ and ‘Client’ project).&lt;br /&gt;6. Compile the ‘Client’ project and make it the Startup Project (Right click on ‘Client’ project and select ‘Set as Startup Project’). Press Ctrl+F5 and you should see the output as shown in figure 7&lt;br /&gt;&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_a0lOQELDZCg/SlZSjAlAlgI/AAAAAAAAADk/TwcdhIIbLhw/s1600-h/7.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 400px; height: 102px;" src="http://1.bp.blogspot.com/_a0lOQELDZCg/SlZSjAlAlgI/AAAAAAAAADk/TwcdhIIbLhw/s400/7.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5356559568207910402" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;b&gt;Fig 7&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Wow, you just create a WCF service from scratch and got it working. Though it may not be simple, I am sure it’s worth a try. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;How it Works&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;&lt;br /&gt;Let me explain some of the concepts discussed in the above sections. If you have read my &lt;a href=” http://dotnetpost.blogspot.com/2009/06/fundamentals-of-windows-communication.html”&gt;previous&lt;/a&gt; post, many of the details should be self explanatory. In listing 1, the IWCFCalculatorService interface is the Service Contract since it is decorated with the &lt;i&gt;[ServiceContract]&lt;/i&gt; attribute. The single method within this interface - AddNumbers – is a WCF method as its decorated with the &lt;i&gt;[OperationContract]&lt;/i&gt; attribute. Since IWCFCalculatorService is a service contract, any class implementing this interface becomes a WCF Service. This is also true for the WCFCalculatorService class as shown in listing 2.&lt;br /&gt;&lt;br /&gt;In listing 3, an instance of ServiceHost class is created. This class provides a host for a WCF Service. It accepts two parameters, &lt;i&gt;Type&lt;/i&gt; and &lt;i&gt;params&lt;/i&gt; respectively. The &lt;i&gt;Type&lt;/i&gt; parameter specifies the type (WCFCalculator.WCFCalculatorService) of the service while &lt;i&gt;params&lt;/i&gt; specifies a collection of addresses (http://localhost:8000/WCFCalculator) where the service can be hosted. Next the ServiceHost defines a new Endpoint by calling the AddServiceEndPoint (). This method accepts two parameters including a contract (WCFCalculator.IWCFCalculatorService) and the type of binding (basicHttp) used by the Endpoint. Once an endpoint is defined, the service is open and available to accept requests from the client.&lt;br /&gt;&lt;br /&gt;For a client to communicate with the service, a proxy is required. In listing 4, the generic ChannelFactory&lt;T&gt; service model type generates the proxy and the related channel stack. This factory uses an instance of the EndpointAddress class which provides a unique network address (which points to the service endpoint) used by the client to communicate with the service. The factory creates a service of type IWCFCalculatorService. Later the generated proxy is used to invoke the required funcationlity. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Summary&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;&lt;br /&gt;In this post, I walked you through creating your first WCF Service. You may find it a bit difficult in the beginning but as you gain experience, WCF is a great tool to work with. In future post, I will talk more about WCF. So stay tuned for more… &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/834688215084300455-7873409244091939861?l=dotnetpost.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetpost.blogspot.com/feeds/7873409244091939861/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetpost.blogspot.com/2009/07/getting-started-with-wcf-service.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/7873409244091939861'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/7873409244091939861'/><link rel='alternate' type='text/html' href='http://dotnetpost.blogspot.com/2009/07/getting-started-with-wcf-service.html' title='Getting Started with WCF Service'/><author><name>Kashif Ahmad</name><uri>http://www.blogger.com/profile/02151423871584093787</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_a0lOQELDZCg/SlZRZ3pGzaI/AAAAAAAAAC0/3gJg18CZR5s/s72-c/1.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-834688215084300455.post-2248666944526667832</id><published>2009-06-30T00:17:00.000-07:00</published><updated>2009-07-09T13:34:07.206-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WCF'/><title type='text'>Fundamentals of Windows Communication Foundation</title><content type='html'>&lt;br&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;In this post, we will look at the fundamental concepts behind Windows Communication Foundation or WCF (formally known as Indigo). This is not a walkthrough post rather it emphasis on the concepts which make up WCF. Creating and working with WCF Services will be a topic of future post. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;What is Windows Communication Foundation&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;WCF is Microsoft’s flagship technology for developing Distributed application. It is a development platform which targets Service-Oriented Architecture. WCF provides a loosely coupled and interoperable platform for developing service-oriented applications.&lt;br /&gt;&lt;br /&gt;Before the introduction of WCF, technologies such as .NET Remoting, COM, DCOM+ and MSMQ have existed for developing distributed applications. The downfall of these technologies has been coupling to a specific technology. Only a .NET Remoting client can talk to a .NET Remoting server. This means that’s its almost impossible for a Java-based client to talk to a .NET Remoting Server. Although Web Services have addressed the issue of interoperability to a greater extent, the introduction of &lt;i&gt;Enhancement&lt;/i&gt; have started yet another race between different vendors.&lt;br /&gt;&lt;br /&gt;To overcome the problem of interoperability and tight coupling, Microsoft introduced Windows Communication Foundation with .NET Framework 3.0. The &lt;i&gt;System.ServiceModel&lt;/i&gt; assembly provides the core functionality for WCF. WCF provides a single programming model for developing distributed applications. It supports different protocols, behaviors and policies. This means the same WCF Service can be exposed to clients using different protocols. This way the service encompassing the business functionality remains the same but has different interfaces to interact with. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;How does a WCF Service Work&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;Before I proceed to explain the different concepts behind WCF, I want to give you a faint idea of how a WCF application is organized. Basically a WCF application consists of three parts:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Service&lt;/b&gt;: The service exposes the business functionality to the rest of the world&lt;br /&gt;&lt;b&gt;Host&lt;/b&gt;: Before a service is available, it must be hosted in an environment. &lt;br /&gt;&lt;b&gt;Client&lt;/b&gt;: The client is an application or yet another service which accesses the service&lt;br /&gt;&lt;br /&gt;Let us now look at the different concepts which make up a WCF application in the following sections. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Service and Contract&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;A &lt;i&gt;service&lt;/i&gt; is a set of business functionality. From a .NET point-of-view, a service represents a &lt;i&gt;CLR type&lt;/i&gt;. This type exposes different methods which can be invoked by client. For a type to be WCF Service, it must have a &lt;i&gt;service contract&lt;/i&gt;. A service contract is defined by applying the &lt;i&gt;[ServiceContract]&lt;/i&gt; attribute on a class or an interface. Any class implementing an interface with associated service contract is also a WCF service. Following listing shows a simple service contract: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;[ServiceContract (Namespace="http://myuniquenamespace/")]&lt;br /&gt;public interface IMaths&lt;br /&gt;{&lt;br /&gt;    [OperationContract]&lt;br /&gt;    int AddTwoNumbers (int x, int y);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;It is quite obvious that a class/interface define methods to be invoked. All methods exposed by a WCF Service must be decorated with the &lt;i&gt;[OperationContract]&lt;/i&gt; attribute. A method without this attribute is not a part of the WCF Service. You must keep in mind that the &lt;i&gt;OperationContract&lt;/i&gt; can only be applied to methods and not to a property or event. Why, because WCF is about exposing business functionality and business functionality resides in methods. For this reason, the &lt;i&gt;OperationContract&lt;/i&gt; is only specific to methods. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Hosting&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;As I mentioned above, before a service can be accessed, it must be hosted in a &lt;i&gt;host process&lt;/i&gt;. A host process can be any Windows Process. We can host multiple services under one host process or vice versa. There are three kinds of hosting available including:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Self Hosting:&lt;/b&gt; In self-hosting, the programmer is responsible for providing a hosting environment for the service which can include a Console application, Windows Form, WPF application or Windows NT Service.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;IIS Hosting:&lt;/b&gt; A service can be hosted like a regular asp.net application. This requires a .svc file to be hosted in IIS&lt;br /&gt;&lt;br /&gt;&lt;b&gt;WAS Hosting:&lt;/b&gt; The Windows Activation Service (WAS) is only available for Windows Vista. Like IIS Hosting, WAS also requires a .svc file and is available for different protocols.&lt;br /&gt;&lt;br /&gt;Under the hood of every host, the WCF Service Model is responsible for handling the communication. The &lt;i&gt;ServiceHost&lt;/i&gt; class (a part of the service model) initiates the communication channel. A ServiceHost has an associated &lt;i&gt;service type, address, service contract and communication protocol&lt;/i&gt;.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Addresses&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;Each WCF service has a unique address which a URI (Universal Resource Identifier). The URI has the following syntax:&lt;br /&gt;&lt;br /&gt;[scheme]://[domain|machine-name][:port]/[optional [path]&lt;br /&gt;&lt;br /&gt;A &lt;i&gt;scheme&lt;/i&gt; defines the transport protocol used for communication. These protocols can include HTTP, TCP, name-pipes, MSMQ etc. Each of these protocols has an associated scheme such as http, net.tcp etc. The &lt;i&gt;domain&lt;/i&gt; is the name of the machine or domain hosting the service. The &lt;i&gt;port&lt;/i&gt; identifies the communication port associated with a specific protocol. A &lt;i&gt;path&lt;/i&gt; can be used to avoid ambiguity. For example, we may have two services hosted on the same address. In this case, the optional path will give a separate address for each hosted service. The following shows a few examples of addresses:&lt;br /&gt;&lt;br /&gt;http://www.mydomain.com&lt;br /&gt;net.tcp://localhost/servicename&lt;br /&gt;net.pipe://localhost:5500/myservice&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Binding&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;&lt;i&gt;Binding&lt;/i&gt; represents the options of choosing from different transport protocols, message encoding formats, security and reliability options for communication. When it comes to using a combination of these features, the options are countless - almost. For example, one may decide to use Http, Https, TCP, MSMQ, Named Pipes etc. as a transport protocol. Message encoding can be based on Binary Serialization or XML formatting. Security is yet another broad area to select from. If we plot a matrix of available options, we will end up with a very long list.&lt;br /&gt;&lt;br /&gt;WCF &lt;i&gt;Binding&lt;/i&gt; simplifies the above process by grouping together different options. For example HttpBasicBinding supports Http/Https protocols, Text/MTOM encoding format and is interoperable between existing and new web services format. Similarly, NetTcpBinding supports TCP protocol, Binary formatting and is not interoperable with other protocols. Details of different binding options can be found &lt;a href=”http://msdn.microsoft.com/en-us/library/ms730879.aspx”&gt;here&lt;/a&gt;.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Endpoint&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;To initiate communication with a service, the service model (ServiceHost) must provide an &lt;i&gt;Endpoint&lt;/i&gt;. An endpoint is basically the trilogy of Address, Binding and Contract (commonly known as the ABC of a service). A service must have at least one endpoint, although it can have multiple endpoints. The ServiceHost must be initialized with one or more endpoints before communication commences.&lt;br /&gt;&lt;br /&gt;Since a service can expose more than one endpoint, the same service is available with different communication options. For example, Service-A may be available over Http for web services but is also is available over TCP behind a firewall. It all comes down to the user requirements but the options are numerous. Endpoints can be configured using config files or programmatically. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Metadata&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;A service is attached to an endpoint where each endpoint has associated address, binding and contract. The client communicates with this endpoint to invoke business functionality. But the client needs to know about the endpoint before interacting with the service. &lt;i&gt;Metadata&lt;/i&gt; provides information about an endpoint to the clients. &lt;i&gt;Metadata&lt;/i&gt; can be generated by the help of a ServiceHost. The ServiceHost can either expose a metadata endpoint (this is different from the service endpoint) or can generate a WSDL file representing the metadata. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Proxy&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;A client can only communicate with a service using a &lt;i&gt;proxy&lt;/i&gt;. A proxy acts on behalf of the service and exposes methods to the client. It also handles the underlying plumbing associated with the communication i.e. it handles message serialization, encoding format etc. A proxy communicates with one endpoint so it’s a one-to-one relationship. Proxies are generated by the help of &lt;i&gt;metadata&lt;/i&gt; of a service.&lt;br /&gt;&lt;br /&gt;With this we come to the end of this post. Future posts will talk about creating WCF Services. So stay tuned for more…&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/834688215084300455-2248666944526667832?l=dotnetpost.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetpost.blogspot.com/feeds/2248666944526667832/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetpost.blogspot.com/2009/06/fundamentals-of-windows-communication.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/2248666944526667832'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/2248666944526667832'/><link rel='alternate' type='text/html' href='http://dotnetpost.blogspot.com/2009/06/fundamentals-of-windows-communication.html' title='Fundamentals of Windows Communication Foundation'/><author><name>Kashif Ahmad</name><uri>http://www.blogger.com/profile/02151423871584093787</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-834688215084300455.post-2597716384563456495</id><published>2009-06-24T23:10:00.000-07:00</published><updated>2009-06-24T23:35:22.384-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='AJAX'/><title type='text'>Dynamic ASP.NET Ajax Accordion Control</title><content type='html'>&lt;br&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;In this post we will take a look at the accordion control. The Accordion control is a part of the &lt;a href=" http://www.codeplex.com/Wiki/View.aspx?ProjectName=AjaxControlToolkit"&gt;AJAX Control Toolkit&lt;/a&gt; which comes as a separate bundle to be used with ASP.NET AJAX. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Accordion Control&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;An accordion control represents a group of panels where only one panel is selectable at a time. Each panel consists of a header and content template. According to &lt;a href=" http://www.asp.net/AJAX/AjaxControlToolkit/Samples/Accordion/Accordion.aspx "&gt;ASP.NET AJAX Website&lt;/a&gt; &lt;i&gt;“An Accordion is a web control that allows you to provide multiple panes and display them one at a time. It is like having several CollapsiblePanels where only one can be expanded at a time”&lt;/i&gt;.&lt;br /&gt;&lt;br /&gt;There are different properties of an accordion which control its look and feel. These properties include:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;SelectIndex:&lt;/b&gt; Specifies the pane to be selected&lt;br /&gt;&lt;b&gt;FadeTransitions:&lt;/b&gt; A boolean value which adds or removes a transition effect to a pane&lt;br /&gt;&lt;b&gt;TransitionDuration:&lt;/b&gt; Specifies the time of transition. This is in milliseconds&lt;br /&gt;&lt;b&gt;RequiredOpenPane:&lt;/b&gt; A boolean value which always keeps one pane open&lt;br /&gt;&lt;b&gt;DataSourceID:&lt;/b&gt; Specifies the data source for building data-bound control&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Data-Binding with Accordion Control&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;An accordion control can display both static and dynamic data. When displaying static data, an accordion uses the &amp;lt;Pane&amp;gt; template. Each pane consists of an &amp;lt;AccordionPane&amp;gt; which in turn consists of a &amp;lt;Header&amp;gt; and &amp;lt;Content&amp;gt; template.&lt;br /&gt;&lt;br /&gt;Listing 1 defines a simple accordion which displays static data using the &amp;lt;Panes&amp;gt; template:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Listing 1&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;&amp;lt;cc1:Accordion &lt;br /&gt;     ID="Accordion2" &lt;br /&gt;     runat="server"&amp;gt;&lt;br /&gt;            &lt;br /&gt;     &amp;lt;Panes&amp;gt;&lt;br /&gt;          &amp;lt;cc1:AccordionPane runat="server" ID="AccordionPane1"&amp;gt;&lt;br /&gt;              &amp;lt;Header&amp;gt;First&amp;lt;/Header&amp;gt;&lt;br /&gt;              &amp;lt;Content&amp;gt;This is the Firt Content Pane &amp;lt;/Content&amp;gt;&lt;br /&gt;          &amp;lt;/cc1:AccordionPane&amp;gt;&lt;br /&gt;          &amp;lt;cc1:AccordionPane runat="server" ID="AccordionPane2"&amp;gt;&lt;br /&gt;              &amp;lt;Header&amp;gt;Second&amp;lt;/Header&amp;gt;&lt;br /&gt;              &amp;lt;Content&amp;gt;This is the Second Content Pane &amp;lt;/Content&amp;gt;&lt;br /&gt;          &amp;lt;/cc1:AccordionPane&amp;gt;&lt;br /&gt;          &amp;lt;cc1:AccordionPane runat="server" ID="AccordionPane3"&amp;gt;&lt;br /&gt;              &amp;lt;Header&amp;gt;Third&amp;lt;/Header&amp;gt;&lt;br /&gt;              &amp;lt;Content&amp;gt;This is the Third Content Pane &amp;lt;/Content&amp;gt;&lt;br /&gt;          &amp;lt;/cc1:AccordionPane&amp;gt;&lt;br /&gt;     &amp;lt;/Panes&amp;gt;                    &lt;br /&gt;&amp;lt;/cc1:Accordion&amp;gt; &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;To build a dynamic accordion control, two points are important. One is to use the &lt;b&gt;DataSourceID&lt;/b&gt; property (which is a standard property of most of the ASP.NET Controls) and second is to use the &lt;b&gt;&amp;lt;HeaderTemplate&amp;gt;&lt;/b&gt; and &lt;b&gt;&amp;lt;ContentTemplate&amp;gt;&lt;/b&gt;. The function of each of these templates is pretty obvious from their names.&lt;br /&gt;&lt;br /&gt;Listing 2 shows a dynamically created accordion control which displays data from the Northwind Database:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Listing 2&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;&amp;lt;cc1:Accordion &lt;br /&gt;            ID="Accordion1" &lt;br /&gt;            runat="server"&lt;br /&gt;            FadeTransitions="true"&lt;br /&gt;            AutoSize="Fill"&lt;br /&gt;            SelectedIndex="0" &lt;br /&gt;            RequireOpenedPane="false"&lt;br /&gt;            TransitionDuration="250"&lt;br /&gt;            DataSourceID="SqlDataSource1"&lt;br /&gt;            Width="500"&amp;gt;&lt;br /&gt;            &lt;br /&gt;            &amp;lt;HeaderTemplate&amp;gt;&lt;br /&gt;                &amp;lt;b&amp;gt;&amp;lt;%#DataBinder.Eval(Container.DataItem, "CustomerID")%&amp;gt;&amp;lt;/b&amp;gt;                &lt;br /&gt;            &amp;lt;/HeaderTemplate&amp;gt;&lt;br /&gt;                    &lt;br /&gt;            &amp;lt;ContentTemplate&amp;gt;&lt;br /&gt;                &amp;lt;table border="1" cellpadding="4" cellspacing="0" width="100%"&amp;gt;&lt;br /&gt;                    &amp;lt;tr&amp;gt;&lt;br /&gt;                        &amp;lt;td width="10%" align="right" class="style1"&amp;gt;&lt;br /&gt;                            &amp;lt;b&amp;gt;Company:&amp;lt;/b&amp;gt;&lt;br /&gt;                        &amp;lt;/td&amp;gt;&lt;br /&gt;                        &amp;lt;td width="90%" class="style1"&amp;gt;&lt;br /&gt;                            &amp;lt;%#DataBinder.Eval (Container.DataItem, "CompanyName")%&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;                        &amp;lt;/td&amp;gt;&lt;br /&gt;                    &amp;lt;/tr&amp;gt;&lt;br /&gt;                    &amp;lt;tr&amp;gt;&lt;br /&gt;                        &amp;lt;td width="10%" align="right" class="style1"&amp;gt;&lt;br /&gt;                            &amp;lt;b&amp;gt;Contact: &amp;lt;/b&amp;gt;&lt;br /&gt;                        &amp;lt;/td&amp;gt;&lt;br /&gt;                        &amp;lt;td width="90%" class="style1"&amp;gt;&lt;br /&gt;                            &amp;lt;%#DataBinder.Eval (Container.DataItem, "ContactName")%&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;                        &amp;lt;/td&amp;gt;&lt;br /&gt;                    &amp;lt;/tr&amp;gt;    &lt;br /&gt;                    &amp;lt;tr&amp;gt;&lt;br /&gt;                        &amp;lt;td width="10%" align="right" class="style1"&amp;gt;&lt;br /&gt;                            &amp;lt;b&amp;gt;Address: &amp;lt;/b&amp;gt;&lt;br /&gt;                        &amp;lt;/td&amp;gt;&lt;br /&gt;                        &amp;lt;td width="90%" class="style1"&amp;gt;&lt;br /&gt;                            &amp;lt;/b&amp;gt;&amp;lt;%#DataBinder.Eval (Container.DataItem, "Address")%&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;                        &amp;lt;/td&amp;gt;&lt;br /&gt;                    &amp;lt;/tr&amp;gt;&lt;br /&gt;                    &amp;lt;tr&amp;gt;&lt;br /&gt;                        &amp;lt;td width="10%" align="right" class="style1"&amp;gt;&lt;br /&gt;                            &amp;lt;b&amp;gt;City: &amp;lt;/b&amp;gt;&lt;br /&gt;                        &amp;lt;/td&amp;gt;&lt;br /&gt;                        &amp;lt;td width="90%" class="style1"&amp;gt;&lt;br /&gt;                            &amp;lt;%#DataBinder.Eval (Container.DataItem, "City")%&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;                        &amp;lt;/td&amp;gt;                    &lt;br /&gt;                    &amp;lt;/tr&amp;gt;&lt;br /&gt;                    &amp;lt;tr&amp;gt;&lt;br /&gt;                        &amp;lt;td width="100%" colspan="2" align="right" class="style1"&amp;gt;&lt;br /&gt;                            &amp;lt;b&amp;gt;&amp;lt;a href="edit.aspx?CustomerID=&amp;lt;%#DataBinder.Eval(Container.DataItem, "CustomerID")%&amp;gt;"&amp;gt;Edit&amp;lt;/a&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;                        &amp;lt;/td&amp;gt;&lt;br /&gt;                    &amp;lt;/tr&amp;gt;&lt;br /&gt;                &amp;lt;/table&amp;gt;&lt;br /&gt;            &amp;lt;/ContentTemplate&amp;gt;&lt;br /&gt;                    &lt;br /&gt;&amp;lt;/cc1:Accordion&amp;gt; &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&amp;lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="&amp;lt;%$ ConnectionStrings:NorthwindConnectionString %&amp;gt;"             &lt;br /&gt;            SelectCommand="SELECT TOP (10) [CustomerID], [CompanyName], [ContactName], [Address], [City] FROM [Customers]"&amp;gt;&lt;br /&gt;&amp;lt;/asp:SqlDataSource&amp;gt; &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Summary&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;The Accordion control comes with ASP.NET AJAX Control Toolkit. An accordion can consists of multiple panes where each pane consists of a header and content template.&lt;br /&gt;&lt;br /&gt;An accordion control has different properties. Many of the properties are used to control the way a pane is rendered or hidden. These properties add animation effects to a pane transition. A data source property also exits to bind an accordion control to a data source.&lt;br /&gt;&lt;br /&gt;An accordion can bind to static or dynamic data. For static data, the &amp;lt;Panes&amp;gt; template is used. To dynamically bind the data, the &amp;lt;/HeaderTemplate&amp;gt; and &amp;lt;ContentTemplate&amp;gt; are used. &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/834688215084300455-2597716384563456495?l=dotnetpost.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetpost.blogspot.com/feeds/2597716384563456495/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetpost.blogspot.com/2009/06/dynamic-aspnet-ajax-accordion-control.html#comment-form' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/2597716384563456495'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/2597716384563456495'/><link rel='alternate' type='text/html' href='http://dotnetpost.blogspot.com/2009/06/dynamic-aspnet-ajax-accordion-control.html' title='Dynamic ASP.NET Ajax Accordion Control'/><author><name>Kashif Ahmad</name><uri>http://www.blogger.com/profile/02151423871584093787</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-834688215084300455.post-8572533118254780222</id><published>2009-05-17T11:29:00.000-07:00</published><updated>2009-05-17T11:35:13.830-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET'/><title type='text'>Exclude Pages from ASP.NET Authentication</title><content type='html'>&lt;br&gt;&lt;span style="font-family:Verdana;"&gt;Recently i discovered an interesting feature of asp.net where we can exclude page(s) from asp.net authentication. Usually once we have asp.net authentication setup, our requests to different pages must be authenticated. But at times we may require to exclude some of the page(s) from this restriction. This can be easily done by adding a &amp;lt;location&amp;gt; section in the web.config file. The &amp;lt;location&amp;gt; tag goes under the &amp;lt;configuration&amp;gt; section and can be defined as following:&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;&amp;lt;location path="excludepage.aspx"&amp;gt;&lt;br /&gt; &amp;lt;system.web&amp;gt;&lt;br /&gt;  &amp;lt;authorization&amp;gt;&lt;br /&gt;   &amp;lt;allow users="*" /&amp;gt;&lt;br /&gt;  &amp;lt;/authorization&amp;gt;&lt;br /&gt; &amp;lt;/system.web&amp;gt;&lt;br /&gt;&amp;lt;/location&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This tag can also be applied to page in a specific folder as following:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&amp;lt;location path="myfolder/excludepage.aspx"&amp;gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;We can have several &amp;lt;location&amp;gt; tags defined for seperate pages in a web.config file. However, if you have many pages to be excluded, a better approach is to move all the pages under one folder and specify this folder in the &amp;lt;location&amp;gt; tag as following:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&amp;lt;location path="myfolder"&amp;gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Do keep in mind that if excluded pages reference a css, image etc file, those too must be excluded in order work properly.&lt;br /&gt;&lt;br /&gt;Hope this post has been helpful. Stay tuned for more...&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/834688215084300455-8572533118254780222?l=dotnetpost.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetpost.blogspot.com/feeds/8572533118254780222/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetpost.blogspot.com/2009/05/exclude-pages-from-aspnet.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/8572533118254780222'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/8572533118254780222'/><link rel='alternate' type='text/html' href='http://dotnetpost.blogspot.com/2009/05/exclude-pages-from-aspnet.html' title='Exclude Pages from ASP.NET Authentication'/><author><name>Kashif Ahmad</name><uri>http://www.blogger.com/profile/02151423871584093787</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-834688215084300455.post-5490347192545348857</id><published>2009-05-13T11:38:00.000-07:00</published><updated>2009-05-13T11:52:21.179-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Crystal Reports'/><title type='text'>Crystal Report with Alternate Row Color</title><content type='html'>&lt;br&gt;&lt;span style="font-family:Verdana;"&gt;In my &lt;a href="http://dotnetpost.blogspot.com/2009/05/creating-crystal-report-with-visual.html"&gt;previous&lt;/a&gt; post, I walked you through creating a simple crystal report in visual studio. I also mentioned that in the following posts, I will touch upon different topics relating to crystal report. Creating a crystal report is easy; however the users always expect better looking reports for their use.&lt;br /&gt;&lt;br /&gt;One of the questions which pops up on many forums is ‘how to have alternate row color’ in a crystal report just like a gridview in asp.net. To have alternate row color in a crystal report, you have to format a section. A section is separated by a gray bar on the report. There are different sections in a report including ReportHeader, PageHeader, GroupHeader, Details and ReportFooter sections. Usually records appear under the Details Section. To have alternate row color, follow these steps:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;1.   Right click on Details Section and select Section Expert…&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_a0lOQELDZCg/SgsUQf9n7NI/AAAAAAAAACc/C4yEc1fWflE/s1600-h/section.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 400px; height: 110px;" src="http://2.bp.blogspot.com/_a0lOQELDZCg/SgsUQf9n7NI/AAAAAAAAACc/C4yEc1fWflE/s400/section.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5335380457240915154" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;2.   In the Section Exert panel, select the Color Tab and click on the formula icon (with x+2 written on it).&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_a0lOQELDZCg/SgsUX-BCaYI/AAAAAAAAACk/Hm1uwCDdOi8/s1600-h/sectionexpert.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 400px; height: 304px;" src="http://3.bp.blogspot.com/_a0lOQELDZCg/SgsUX-BCaYI/AAAAAAAAACk/Hm1uwCDdOi8/s400/sectionexpert.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5335380585567381890" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;3.   In the Formula Section panel, we have to write code to change the color for alternate rows.&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_a0lOQELDZCg/SgsUgxWhyMI/AAAAAAAAACs/iX70ulyJKNg/s1600-h/formula.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 400px; height: 300px;" src="http://2.bp.blogspot.com/_a0lOQELDZCg/SgsUgxWhyMI/AAAAAAAAACs/iX70ulyJKNg/s400/formula.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5335380736786680002" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;4.   Enter the following code as in listing 1 and click on Save and close icon at the top.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Listing 1&lt;/b&gt; &lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;IF RecordNumber mod 2 = 0 Then&lt;br /&gt;    crRed&lt;br /&gt;Else&lt;br /&gt;    NoColor&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;Now when you view the report, you will see alternate rows with a red background. That is all required to have the required alternate coloring effect. Hope this post was useful for you. Stay tuned for more…&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/834688215084300455-5490347192545348857?l=dotnetpost.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetpost.blogspot.com/feeds/5490347192545348857/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetpost.blogspot.com/2009/05/crystal-report-with-alternate-row-color.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/5490347192545348857'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/5490347192545348857'/><link rel='alternate' type='text/html' href='http://dotnetpost.blogspot.com/2009/05/crystal-report-with-alternate-row-color.html' title='Crystal Report with Alternate Row Color'/><author><name>Kashif Ahmad</name><uri>http://www.blogger.com/profile/02151423871584093787</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_a0lOQELDZCg/SgsUQf9n7NI/AAAAAAAAACc/C4yEc1fWflE/s72-c/section.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-834688215084300455.post-496239983444933216</id><published>2009-05-13T05:45:00.001-07:00</published><updated>2009-05-13T11:51:59.509-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Crystal Reports'/><title type='text'>Creating Crystal Report with Visual Studio</title><content type='html'>&lt;br&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Introduction&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;Crystal Reports is a power reporting tool which ships with visual studio. It greatly enhances the process of creating reports. Crystal reports provide a &lt;i&gt;Rapid Application Development&lt;/i&gt; style reporting model for both web and windows applications. Although creating reports with visual studio is a breeze, however; it takes some time and efforts to get acquainted with many of crystal report features. In this and following posts on crystal reports, we will have a look at these concepts to get a handle on crystal reports. &lt;br /&gt;&lt;br /&gt;Crystal Reports integrate seamlessly with Visual Studio. Crystal reports works with ADO.NET, web services, flat files, MS Access and XML. We can easily export data from crystal reports to different formats including PDF, MS Word &amp; Excel and Rich Text Format. The Crystal Reports API provides a rich programming model for creating and customizing reports. Before we dive into creating our first reports, following are some of concepts you should understand.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Data Access Model&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;Crystal Reports can either use a &lt;i&gt;Push&lt;/i&gt; or a &lt;i&gt;Pull&lt;/i&gt; model to access data. In a pull model, the crystal report engine connects to the data source through a driver, executes SQL Commands against the data source and publishes the data on the report.&lt;br /&gt;&lt;br /&gt;In a push model, the task of talking to the data source is left with the developer. The developer writes the code to hold the data in a data container such as a dataset, datatable or a custom collection and then later assigns it to the report. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Use Page_Init Method&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;On many of the forums, a problem commonly observed is that a report does not display properly when any of the button on the report toolbar (every report has a report toolbar at the top with different functionality) is clicked. Why this happens is due to a simple reason – &lt;i&gt;Don’t use the Page_Load method&lt;/i&gt;. The data which binds and provides login information to a crystal report should always reside in the &lt;b&gt;Page_Init&lt;/b&gt; method. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Creating Crystal Report using Visual Studio&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;Creating a crystal report with visual studio is straight forward. In this section, I will walk you through creating a crystal report for a web application. I will use a step-by-step approach for the readers. So lets get started:&lt;br /&gt;&lt;br /&gt;1. Create a new a new web site in Visual Studio.&lt;br /&gt;2. In the solution explorer, right click and click on &lt;b&gt;Add New Item&lt;/b&gt;.&lt;br /&gt;3. In the &lt;b&gt;Add New Item Template&lt;/b&gt;, select Crystal Report. In the &lt;b&gt;Name&lt;/b&gt; field, type NorthwindProductReport.rpt. Click Add.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_a0lOQELDZCg/SgrBUramtDI/AAAAAAAAAA0/ijxAADLvLAk/s1600-h/1.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 202px;" src="http://1.bp.blogspot.com/_a0lOQELDZCg/SgrBUramtDI/AAAAAAAAAA0/ijxAADLvLAk/s320/1.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5335289269569631282" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;b&gt;Fig 1&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;4. A new dialog box &lt;b&gt;Crystal Reports Gallery&lt;/b&gt; appears. Select the &lt;b&gt;Using the Report Wizard&lt;/b&gt; option under the &lt;b&gt;Create New Crystal Report Document&lt;/b&gt; panel. Also select the &lt;b&gt;Standard&lt;/b&gt; option under the &lt;b&gt;Choose an Expert&lt;/b&gt; panel and click Ok. &lt;br /&gt;&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_a0lOQELDZCg/SgrBjPb08MI/AAAAAAAAAA8/GNVqx1cdbM0/s1600-h/2.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 262px; height: 320px;" src="http://1.bp.blogspot.com/_a0lOQELDZCg/SgrBjPb08MI/AAAAAAAAAA8/GNVqx1cdbM0/s320/2.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5335289519756603586" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Fig 2&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;5. The &lt;b&gt;Standard Report Creation Wizard&lt;/b&gt; dialog box appears. Under the &lt;b&gt;Available Data Sources&lt;/b&gt; panel, expand the nodes &lt;b&gt;Create New Connection&lt;/b&gt; and &lt;b&gt;OLE DB (ADO)&lt;/b&gt;. &lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_a0lOQELDZCg/SgrBxt9H2sI/AAAAAAAAABE/BvKrVW3HaVY/s1600-h/3.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 268px;" src="http://2.bp.blogspot.com/_a0lOQELDZCg/SgrBxt9H2sI/AAAAAAAAABE/BvKrVW3HaVY/s320/3.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5335289768467487426" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Fig 3&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;6. A new &lt;b&gt;OLE DB (ADO)&lt;/b&gt; dialog appears. Under the &lt;b&gt;Provider&lt;/b&gt; panel, select &lt;b&gt;Microsoft OLE DB Provider for SQL Server&lt;/b&gt;. Click Next. &lt;br /&gt;&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_a0lOQELDZCg/SgrB7nKSJ6I/AAAAAAAAABM/DhIIVfgMfu8/s1600-h/4.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 311px; height: 320px;" src="http://1.bp.blogspot.com/_a0lOQELDZCg/SgrB7nKSJ6I/AAAAAAAAABM/DhIIVfgMfu8/s320/4.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5335289938442332066" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Fig 4&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;7. Under the &lt;b&gt;Connection Information&lt;/b&gt; panel, enter in the &lt;b&gt;Server&lt;/b&gt;, &lt;b&gt;User ID&lt;/b&gt;, &lt;b&gt;Password&lt;/b&gt; fields. Select &lt;b&gt;Northwind&lt;/b&gt; Database. Click Finish.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_a0lOQELDZCg/SgrCEXd-OJI/AAAAAAAAABU/GSUmWtxrQaM/s1600-h/5.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 311px; height: 320px;" src="http://4.bp.blogspot.com/_a0lOQELDZCg/SgrCEXd-OJI/AAAAAAAAABU/GSUmWtxrQaM/s320/5.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5335290088848767122" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Fig 5&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;8. You return to the &lt;b&gt;Standard Report Creation Wizard&lt;/b&gt; dialog. The &lt;b&gt;OLE DB (ADO)&lt;/b&gt; has a new connection to the &lt;b&gt;Northwind&lt;/b&gt; database. Expand the &lt;b&gt;Northwind&lt;/b&gt;, dbo, Tables and select Products. Click the &gt; symbol to move the Products table to the &lt;b&gt;Selected Tables&lt;/b&gt; panel. Click Next.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_a0lOQELDZCg/SgrCML--TlI/AAAAAAAAABc/SetfNLMJrtY/s1600-h/6.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 268px;" src="http://3.bp.blogspot.com/_a0lOQELDZCg/SgrCML--TlI/AAAAAAAAABc/SetfNLMJrtY/s320/6.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5335290223204912722" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Fig 6&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;9. Under &lt;b&gt;Fields&lt;/b&gt; and &lt;b&gt;Available Fields&lt;/b&gt; panels, expand the node &lt;b&gt;Products&lt;/b&gt;. Select &lt;b&gt;ProductID&lt;/b&gt;, &lt;b&gt;ProductName&lt;/b&gt;, &lt;b&gt;QuantityPerUnit&lt;/b&gt; and &lt;b&gt;Unit Price&lt;/b&gt; by holding the Ctrl Key. Click the &gt; symbol to move these fields to the &lt;b&gt;Fields to Display&lt;/b&gt; panel. Click Next.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_a0lOQELDZCg/SgrCUJqE_rI/AAAAAAAAABk/4jZ7ykuswOE/s1600-h/7.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 268px;" src="http://1.bp.blogspot.com/_a0lOQELDZCg/SgrCUJqE_rI/AAAAAAAAABk/4jZ7ykuswOE/s320/7.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5335290360019353266" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Fig 7&lt;/b&gt;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;10. Under &lt;b&gt;Grouping&lt;/b&gt; and &lt;b&gt;Available Fields&lt;/b&gt; panels select the &lt;b&gt;Products.ProductID&lt;/b&gt; field and click the &gt; symbol to move the field to the &lt;b&gt;Group By&lt;/b&gt; panel (&lt;i&gt;Note: The Grouping function is similar to Group By clause in SQL Server. If there are multiple records for a grouping field, they are grouped together e.g. we can group Orders by Customers in a report&lt;/i&gt;). Click Finish.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_a0lOQELDZCg/SgrCfwib82I/AAAAAAAAABs/oktwK58ZuSo/s1600-h/8.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 283px;" src="http://3.bp.blogspot.com/_a0lOQELDZCg/SgrCfwib82I/AAAAAAAAABs/oktwK58ZuSo/s320/8.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5335290559434847074" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Fig 8&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;11. The report is created with four fields on it. You can change its properties by right clicking on it and selecting Format Object. You an also add different objects on this report including a line, box and custom text to layout the report.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_a0lOQELDZCg/SgrCoZ4zkII/AAAAAAAAAB0/yknqLD8964Y/s1600-h/9.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 144px;" src="http://1.bp.blogspot.com/_a0lOQELDZCg/SgrCoZ4zkII/AAAAAAAAAB0/yknqLD8964Y/s320/9.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5335290707973476482" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Fig 9&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;12. At the bottom of the report, you will find two tabs &lt;b&gt;Main Report&lt;/b&gt; and &lt;b&gt;Main Report Preview&lt;/b&gt;. Click on &lt;b&gt;Main Report Preview&lt;/b&gt; to preview the report.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_a0lOQELDZCg/SgrCzA-oYBI/AAAAAAAAAB8/TZ4ujukEOpk/s1600-h/10.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 281px;" src="http://1.bp.blogspot.com/_a0lOQELDZCg/SgrCzA-oYBI/AAAAAAAAAB8/TZ4ujukEOpk/s320/10.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5335290890265583634" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Fig 10&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;13. Now that we have created that report, we can easily embed it in a web page using minimal code. For this purpose, right click on solution explorer and click on &lt;b&gt;Add New Item&lt;/b&gt;. In the &lt;b&gt;Templates&lt;/b&gt; view, select &lt;b&gt;Web Form&lt;/b&gt; and type Products in the &lt;b&gt;Name&lt;/b&gt; field. Click Add.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_a0lOQELDZCg/SgrC6HhHWMI/AAAAAAAAACE/sp1C2gXL9mU/s1600-h/11.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 203px;" src="http://4.bp.blogspot.com/_a0lOQELDZCg/SgrC6HhHWMI/AAAAAAAAACE/sp1C2gXL9mU/s320/11.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5335291012279916738" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Fig 11&lt;/b&gt;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;14. On the web form, drag an instance of &lt;b&gt;CrystalReportViewer&lt;/b&gt; from the &lt;b&gt;Toolbox -&gt; Reporting&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_a0lOQELDZCg/SgrDBNbm9_I/AAAAAAAAACM/g3TUF1kfzk4/s1600-h/12.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 101px;" src="http://3.bp.blogspot.com/_a0lOQELDZCg/SgrDBNbm9_I/AAAAAAAAACM/g3TUF1kfzk4/s320/12.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5335291134126520306" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Fig 12&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;15. In &lt;b&gt;Code View&lt;/b&gt;, declare Page_Init method as in listing 1: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Listing 1&lt;/b&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;protected void Page_Init(object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;    BuildReport ();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;Next code the private BuildReport method described in listing 2 used in the above code: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Listing 2&lt;/b&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;private void BuildReport ()&lt;br /&gt;{&lt;br /&gt;    ConnectionInfo connInfo = new ConnectionInfo ();&lt;br /&gt;&lt;br /&gt;    connInfo.ServerName     = "Personal";&lt;br /&gt;    connInfo.DatabaseName   = "Northwind";&lt;br /&gt;    connInfo.UserID         = "reportuser";&lt;br /&gt;    connInfo.Password       = "secretlogin";&lt;br /&gt;&lt;br /&gt;    CrystalReportViewer1.ReportSource = Server.MapPath ("NorthwindProductReport.rpt");&lt;br /&gt;    ReportLogon (connInfo);&lt;br /&gt;    ReportLogon (connInfo);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;Finally, the above code calls the method ReportLogon described in listing 3: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Listing 3&lt;/b&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;private void ReportLogon (ConnectionInfo connectionInfo)&lt;br /&gt;{&lt;br /&gt;    TableLogOnInfos tableLogOnInfos = CrystalReportViewer1.LogOnInfo;&lt;br /&gt;&lt;br /&gt;    foreach (TableLogOnInfo tableLogOnInfo in tableLogOnInfos)&lt;br /&gt;    {&lt;br /&gt;        tableLogOnInfo.ConnectionInfo = connectionInfo;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;&lt;br /&gt;16. Now if you run the application, you will see a report displayed as following: &lt;br /&gt;&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_a0lOQELDZCg/SgrDLS77_8I/AAAAAAAAACU/Oaqxn_29KOo/s1600-h/13.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 304px;" src="http://1.bp.blogspot.com/_a0lOQELDZCg/SgrDLS77_8I/AAAAAAAAACU/Oaqxn_29KOo/s320/13.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5335291307402985410" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Fig 13&lt;/b&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Summary&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;In this post, I walked you through creating a simple crystal report. This is just the tip of the iceberg. There is so much more to be done with crystal reports. In my following posts, I will touch on different topics relating to crystal reports. Some of them will be walkthroughs while others will be tips to help you write better crystal reports. So stay tuned for more…&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/834688215084300455-496239983444933216?l=dotnetpost.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetpost.blogspot.com/feeds/496239983444933216/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetpost.blogspot.com/2009/05/creating-crystal-report-with-visual.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/496239983444933216'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/496239983444933216'/><link rel='alternate' type='text/html' href='http://dotnetpost.blogspot.com/2009/05/creating-crystal-report-with-visual.html' title='Creating Crystal Report with Visual Studio'/><author><name>Kashif Ahmad</name><uri>http://www.blogger.com/profile/02151423871584093787</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_a0lOQELDZCg/SgrBUramtDI/AAAAAAAAAA0/ijxAADLvLAk/s72-c/1.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-834688215084300455.post-2930743984322026455</id><published>2009-03-23T09:52:00.000-07:00</published><updated>2009-07-09T13:34:22.150-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET'/><title type='text'>Reading a CSV File in ASP.NET</title><content type='html'>&lt;br&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;Recently I came across a programming need of reading a CSV (Comma Separated Values) file in ASP.NET. Thanks to ADO.NET, reading a CSV file in ASP.NET is a breeze. I am writing this post to share my understanding with you. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Reading a CSV File&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;A comma-separated-value (CSV) file is commonly used for daily programming needs. CSV files are used to import/export data from databases and spreadsheets. These are simple text file (*.txt, *.csv, *.dat) where data values are separated by a comma or some other character. Usually, the first row has the column-names followed by rows of data. Each row has the data in columns separated by some character. Following is a sample (Northing database – Customers table) of what data looks like in a CSV file with the first row having column-names:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;CustomerID, CompanyName, ContactName, ContactTitle&lt;/b&gt;&lt;br /&gt;ALFKI, Alfreds Futterkiste, Maria Anders, Sales Representative&lt;br /&gt;ANATR, Ana Trujillo Emparedados y helados, Ana Trujillo, Owner&lt;br /&gt;&lt;br /&gt;In ASP.NET, we can easily read and get data from a CSV file using ADO.NET. Listing 1 illustrates the code for reading a CSV file:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Listing 1&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;// filePath: Path where file resides&lt;br /&gt;// filename: File name to be read&lt;br /&gt;private DataTable ReadCSVFile (string filePath, string fileName)&lt;br /&gt;{&lt;br /&gt;    string              connString;&lt;br /&gt;    OleDbConnection     conn;&lt;br /&gt;    OleDbDataAdapter    da;&lt;br /&gt;    OleDbCommand        cmd;&lt;br /&gt;    DataTable           dt;&lt;br /&gt;&lt;br /&gt;    connString  = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath +&lt;br /&gt;                  ";Extended Properties='text;HDR=Yes;FMT=Delimited'";&lt;br /&gt;&lt;br /&gt;    conn = new OleDbConnection (connString);&lt;br /&gt;    conn.Open ();&lt;br /&gt;&lt;br /&gt;    cmd = new OleDbCommand ("SELECT * FROM " + fileName, conn);&lt;br /&gt;    da  = new OleDbDataAdapter (cmd);&lt;br /&gt;    dt  = new DataTable ();&lt;br /&gt;&lt;br /&gt;    da.Fill (dt);&lt;br /&gt;&lt;br /&gt;    return dt;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;&lt;br /&gt;The above code is straight forward with a few points:&lt;br /&gt;&lt;br /&gt;1. In the connection string, HDR stands for header indicating that the first row has the column-names.&lt;br /&gt;2. Similarly, FMT stands for format and specifies the formatting type. By default it is set to &lt;i&gt;Delimited&lt;/i&gt; which specifies a comma-delimited value. The other values include &lt;i&gt;Delimited (x)&lt;/i&gt; where x is the specific character, &lt;i&gt;TabDelimited&lt;/i&gt; which specifies tab-delimited values and &lt;i&gt;FixeLength&lt;/i&gt; which specifies fields with fixed length.&lt;br /&gt;3. The filePath specifies the file path on the machine hosting the application. If the application is hosted on the server then filePath reflects path on the server.&lt;br /&gt;&lt;br /&gt;For your interest I would like to mention that we can also make a join between different CSV files. For example, we can use the following query to join two files.&lt;br /&gt;&lt;br /&gt;“SELECT * FROM fileName1 f1, fileName2 f2 WHERE f1.CustomerID = f2.CustID”;&lt;br /&gt;&lt;br /&gt;Hope this post has been useful for you. Stay tuned for more…&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/834688215084300455-2930743984322026455?l=dotnetpost.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetpost.blogspot.com/feeds/2930743984322026455/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetpost.blogspot.com/2009/03/reading-csv-file-in-aspnet.html#comment-form' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/2930743984322026455'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/2930743984322026455'/><link rel='alternate' type='text/html' href='http://dotnetpost.blogspot.com/2009/03/reading-csv-file-in-aspnet.html' title='Reading a CSV File in ASP.NET'/><author><name>Kashif Ahmad</name><uri>http://www.blogger.com/profile/02151423871584093787</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-834688215084300455.post-2669745495563410270</id><published>2009-03-21T00:38:00.000-07:00</published><updated>2009-03-21T21:02:45.057-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='LINQ'/><title type='text'>LINQ Explained – Part 3</title><content type='html'>&lt;br&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;This is the third part of my on-going series on LINQ. In the &lt;a href="http://dotnetpost.blogspot.com/2008/12/linq-explained-part-2.html"&gt;second&lt;/a&gt; part, we looked at some of the underlying C# features which are important to understand to work with LINQ. In this part, we will conclude with the rest of the features. So let us dive in straight.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Yield Statement&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;The &lt;i&gt;Yield&lt;/i&gt; statement was introduced with C# 2.0. In my previous &lt;a href="http://dotnetpost.blogspot.com/2008/12/linq-explained-part-2.html"&gt;post&lt;/a&gt;, we talked about Enumerators. Enumerators help us iterate through collections and custom classes. Collections and custom classes must implement the IEnumerable interface. This interface has one method, GetEnumerator, which returns an instance of IEnumerator interface. The IEnemrator interface performs the actual iteration.&lt;br /&gt;&lt;br /&gt;All this is pretty straight forward but does require some coding on behalf of the developers. Implementing IEnumerator interface for complex classes can be time consuming. Wouldn’t it be nice if the compiler could handle the enumeration process for us? Thanks to the yield statement, this is still possible.&lt;br /&gt;&lt;br /&gt;Let me explain this concept by the help of the following simple example: &lt;br /&gt;&lt;br /&gt;&lt;b&gt;Listing 1&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;protected void Button1_Click (object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;    foreach (string fruit in BuyFruits ()) // ref 1&lt;br /&gt;    {&lt;br /&gt;        ListBox1.Items.Add (fruit);&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;private IEnumerable BuyFruits ()&lt;br /&gt;{  &lt;br /&gt;    string [] fruits = new string [] {"apple", "orange", "coconut", "papaya", &lt;br /&gt;                                      "mango"};&lt;br /&gt;&lt;br /&gt;    for (int i = 0; i &amp;lt;= fruits.Length - 1; i++)&lt;br /&gt;    {&lt;br /&gt;        yield return fruits [i]; // ref 2&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;If you have noticed, BuyFruits method has a return type of IEnumerable (reference type) but it returns a string (value type) using the &lt;i&gt;yield return&lt;/i&gt; statement. Although BuyFruits is a method, it is acting as a class which performs iteration. This may look  strange but under the hood, two things are happening.&lt;br /&gt;&lt;br /&gt;First, the yield statement, a compiler directive, instructs the compiler to generate an inner (nested) class which implements the IEnumerator interface. It is this inner class which handles iteration for us. Fig 1 shows this class which has been generated using the ILDASM tool. The nested class is named as &lt;BuyFruits&gt;d__0 and implements the generic and non-generic versions of IEnumerable interface. It also implements the member functions including MoveNext, Reset method and Current property. &lt;br /&gt;&lt;br /&gt;&lt;b&gt;Fig 1&lt;/b&gt;&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_a0lOQELDZCg/ScSZ_U23WbI/AAAAAAAAAAc/y8kKlzdhO98/s1600-h/Enumerator.jpg"&gt;&lt;img style="float:none; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 320px; height: 221px;" src="http://3.bp.blogspot.com/_a0lOQELDZCg/ScSZ_U23WbI/AAAAAAAAAAc/y8kKlzdhO98/s320/Enumerator.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5315542773413665202" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;Second, the &lt;i&gt;yield statement&lt;/i&gt; returns a single element at a time but maintains state between calls. This means that each subsequent call to &lt;i&gt;yield return&lt;/i&gt; statement will return the next element in the collection. This is possible because the compiler maintains a state engine which resumes execution from the previously returned value. &lt;br /&gt;&lt;br /&gt;The first time the yield statement is executed in the loop, a new object of the inner (mentioned above) class is created. This instance is used across the loop until it iterates through and reaches the end of the entire collection. Each &lt;i&gt;yield return&lt;/i&gt; is delegated to the MoveNext method of the inner class. After the loop terminates, the instance of the inner class is also disposed. A new instance is created for each new call. This makes it type-safe across calls.&lt;br /&gt; &lt;br /&gt;The code in Listing 1 works under the above principles. First, a class implementing the IEnumerator interface is generated (Fig 1). Next in the Button1_Click event, the foreach loop calls the BuyFruits method. The first call will create an instance of the generated class. Each &lt;i&gt;yield return&lt;/i&gt; call is then delegated to the MoveNext method. This way it iterates through the entire collection.&lt;br /&gt;&lt;br /&gt;We can also implement enumeration for a custom collection using the yield statement. Following is the code for the custom collection:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Listing 2&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;public class FruitCollection : IEnumerable&lt;br /&gt;{ &lt;br /&gt;    private string[] fruits;&lt;br /&gt;&lt;br /&gt;    public FruitCollection ()&lt;br /&gt;    {&lt;br /&gt;        fruits = new string[] {"banana", "apple", "mango", "apricot", &lt;br /&gt;                                          "kiwi"};&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    public IEnumerator GetEnumerator ()&lt;br /&gt;    {&lt;br /&gt;        foreach (string fruit in fruits)&lt;br /&gt;        {&lt;br /&gt;            yield return fruit;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;protected void Button1_Click(object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;    FruitCollection basket = new FruitCollection ();&lt;br /&gt;&lt;br /&gt;    foreach (string fruit in basket)&lt;br /&gt;    { &lt;br /&gt;        ListBox1.Items.Add (fruit);&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;The FruitCollection class implements the IEnumerable interface so GetEnumerator method must be implemented. Within this method, a list of strings is iterated using the yield statement (Note: We can use any looping technique). As mentioned above, a private nested class is generated. This class performs enumeration on behalf of FruitCollection for each &lt;i&gt;yield return&lt;/i&gt; statement. The rest of the process is the same as mentioned above. We can then iterate throught the collection as shown in the Button1_Click event.&lt;br /&gt;&lt;br /&gt;The &lt;i&gt;yield break&lt;/i&gt; statement is another dialect of the yield statement. This statement can stop iteration at any point in the loop. The following snippet will only return the first string in the array.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Listing 3&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;private IEnumerable BuyFruits()&lt;br /&gt;{&lt;br /&gt;    string[] fruits = new string[] {"apple", "orange", "coconut", "papaya", &lt;br /&gt;                                      "mango"};&lt;br /&gt;&lt;br /&gt;    for (int i = 0; i &amp;lt;= fruits.Length - 1; i++)&lt;br /&gt;    {            &lt;br /&gt;        if (i &amp;gt; 1)&lt;br /&gt;            yield break;&lt;br /&gt;&lt;br /&gt;        yield return fruits[i];&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;One last point to mention is that yield statement is equally applicable to generic and non-generic types. For generic types, the IEnumerable&lt;T&gt; interface is used. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Extension Methods&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;Extension methods are one of the new features added to C# 3.0. According to MSDN “Extension method enable you to ‘add’ methods to existing types without creating a new derived type, recompiling or otherwise modifying the original type”. As the definition implies, we can add new functionality to existing types, primitive or custom. &lt;br /&gt;&lt;br /&gt;Extension methods are a special breed of static methods which are invoked like regular instance methods. Extension methods can be added to existing primitive types, classes, structures and interfaces. These methods are static and are defined in a separate static class. Importantly, the first parameter in an extension method defines the type the method will operate on. This parameter must be preceded by &lt;i&gt;this&lt;/i&gt; keyword. For example an extension method with first parameter as &lt;i&gt;this string input&lt;/i&gt; is available for string data types and &lt;i&gt;input&lt;/i&gt; represents the string which invoked the extension method. &lt;br /&gt;&lt;br /&gt;Let us see a simple example of an extension method. The following method adds a greeting message to a string type:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Listing 4&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;public static class GreetingsClass&lt;br /&gt;{ &lt;br /&gt;    public static string AddGreetings (this string name) //note the input parameter&lt;br /&gt;    {&lt;br /&gt;        return String.Concat ("We welcome you ", name);&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;We can now invoke the AddGreetings method with the following code: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;protected void Button1_Click(object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;    string emp = "Employee";&lt;br /&gt;&lt;br /&gt;    txtMessage.Text = emp.AddGreetings ();//invoked as a regular method&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;The extension method AddGreetings is defined in a separate static class. The first parameter of the method preceded by &lt;i&gt;this&lt;/i&gt; keyword makes it an extension method. Using Intellisence, if we look at the list of available methods for the string ‘emp’, we can locate AddGreetings method along other methods.&lt;br /&gt;&lt;br /&gt;Extension methods can also be added to existing .NET classes. In listing 5, an extension method is added to the built-in Stack class. The extension method finds all items in an integer stack which have a value greater than the input parameter. &lt;br /&gt;&lt;br /&gt;&lt;b&gt;Listing 5&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;public static class StackExtender&lt;br /&gt;{&lt;br /&gt;    public static int ItemsGreaterThanInput (this Stack stack, int maxValue)&lt;br /&gt;    {&lt;br /&gt;        int count = 0;&lt;br /&gt;&lt;br /&gt;        foreach (object o in stack)&lt;br /&gt;        {&lt;br /&gt;            if (Convert.ToInt32(o) &amp;gt; maxValue)&lt;br /&gt;                count++;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        return count;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;protected void Button1_Click(object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;    Stack intStack = new Stack ();&lt;br /&gt;&lt;br /&gt;    intStack.Push(5);&lt;br /&gt;    intStack.Push(4);&lt;br /&gt;    intStack.Push(1);&lt;br /&gt;    intStack.Push(8);&lt;br /&gt;&lt;br /&gt;    TextBox1.Text = "Total integers greater than (2) = " + intStack.ItemsGreaterThanInput(2).ToString();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;The above code is pretty straight forward but it has two parameters. The first parameter is the type (Stack) on which it operates. The second is a required parameter which should be provided when this method is invoked. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Var keyword&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;C# 3.0 introduced another useful feature, the &lt;i&gt;var&lt;/i&gt; keyword which allows us to declare implicitly typed variables. An explicit type declaration of these variables is not required which is handled by the compiler. The following line declares a variable of type string which is inferred by the compiler:&lt;br /&gt;&lt;br /&gt;var greet = “Hello World”; // no use of string type&lt;br /&gt;&lt;br /&gt;It is important to note that these variable types are strongly typed. A proof of this is that the type of these variables cannot be changed later on. For example, the above statement will result in an error &lt;b&gt;“Cannot implicitly convert type 'int' to 'string'&lt;/b&gt; if later used as:&lt;br /&gt;&lt;br /&gt;greet = 10;&lt;br /&gt;&lt;br /&gt;The &lt;i&gt;var&lt;/i&gt; keyword can only be used with local variables. An attempt to use it with class level variables will result in an error &lt;b&gt;”The contextual keyword 'var' may only appear within a local variable declaration”&lt;/b&gt;. Since the compiler infers the type of these variables so they ‘must be’ initialized when declared. &lt;br /&gt;&lt;br /&gt;The &lt;i&gt;var&lt;/i&gt; keyword also rids us of extra type declaration. For example, the following code:&lt;br /&gt;&lt;br /&gt;ArrayList alst = new ArrayList ();&lt;br /&gt;&lt;br /&gt;can also be written as:&lt;br /&gt;&lt;br /&gt;var alst = new ArrayList ();&lt;br /&gt;&lt;br /&gt;Similarly, the value returned from a method can also be assigned to a ‘var’ variable. For example, the following method returns an ArrayList: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;private ArrayList GetMyList()&lt;br /&gt;{&lt;br /&gt;    ArrayList alst = new ArrayList ();&lt;br /&gt;    // use alst;&lt;br /&gt;    return alst;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;This method can be directly assigned to the ‘var’ variable:&lt;br /&gt;&lt;br /&gt;var myList = GetList ();&lt;br /&gt;&lt;br /&gt;If we change the implementation of the above method to return an instance of IList, the compiler is still smart enough to infer the type. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Anonymous Types&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;Anonymous types are a new feature added to C# 3.0. The idea is to create a type on the fly without actually declaring it. The compiler infers the type at runtime. This gives us a lot of flexibility in defining new types without actually declaring them. &lt;br /&gt;&lt;br /&gt;How a type is created ‘just like that’ is based on the concept of &lt;i&gt;&lt;b&gt;object initialization&lt;/b&gt;&lt;/i&gt;. Object initialization was also introduced with C# 3.0. The idea is to initialize properties when creating objects without invoking the constructor. Let us consider the class in listing 6 (&lt;i&gt;for those who are new, we can now use ‘automatic properties’ where a variable per property is not required&lt;/i&gt;):&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Listing 6&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;public class Fruit&lt;br /&gt;{&lt;br /&gt;    // automatic properties&lt;br /&gt;    public string FruitName { get; set; } &lt;br /&gt;    public int FruitPrice { get; set; }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;The above class can be instantiated as following:&lt;br /&gt;&lt;br /&gt;Fruit fruit = new Fruit ();&lt;br /&gt;fruit.FruitName = “apple”;&lt;br /&gt;fruit.FruitPrice = 10;&lt;br /&gt;&lt;br /&gt;The above snippet is straightforward but can be time consuming for large classes. Using object initialization, we can reduce the amount of work required to initialize a class with the following syntax:&lt;br /&gt;&lt;br /&gt;Fruit fruit = new Fruit {FruitName = “apple”, FruitPrice = 10 };&lt;br /&gt;&lt;br /&gt;The concept can be further extended to generic types as following: &lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;List&amp;lt;Fruit&amp;gt; basket = new List&amp;lt;Fruit&amp;gt;{&lt;br /&gt; new Fruit {FruitName = “apple”, FruitPrice = 10 },&lt;br /&gt; new Fruit {FruitName = “mango”, FruitPrice = 15}&lt;br /&gt;};&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;Coming back to anonymous types, these are created at runtime. Creating an anonymous type is facilitated by ‘object initialization’ and ‘var’ keyword. The following snippet creates an anonymous type - Employee:&lt;br /&gt;&lt;br /&gt;var Employee = new { Name = “Emp1”, Age = 35, Salary = 3000  };&lt;br /&gt;&lt;br /&gt;We can even create a nested anonymous type using the same syntax. For example, the above code can be extended to add a nested type Address as:&lt;br /&gt;&lt;br /&gt;var Employee = new { Name = “Emp1”, Age = 35, Salary = 3000,&lt;br /&gt;                                  Address = new { HouseNo = “H1”, Block = 3, City = “MyCity” }  &lt;br /&gt;                              };&lt;br /&gt;&lt;br /&gt;Anonymous methods are extensively used in LINQ. The following post will describe this concept further. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Lambda Expressions and Anonymous Methods&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;Lambda Expressions are a new feature added to C# 3.0. They provide a handy way to write concise code. But before we jump on to this topic, it is important to understand anonymous methods.&lt;br /&gt;&lt;br /&gt;C# 2.0 introduced the concept of ‘anonymous methods’. As the name implies, these are name-less methods which can be declared inline. The method is declared and implemented at the same place. The idea is to avoid defining a separate method which is not reused. &lt;br /&gt;&lt;br /&gt;An anonymous method can be used implicitly at a place where a delegate is expected. As we know, when a delegate is called, the referenced method is invoked. In case of an anonymous method, the delegate is replaced by piece of code - inline. The anonymous method is defined using the &lt;i&gt;delegate&lt;/i&gt; keyword followed by an optional list of parameters (within parenthesis) and the body of the method. If an anonymous method doesn’t have any parameters, we can omit the parameter parenthesis. An expression defining an anonymous method is known as anonymous-method-expression and has following syntax:&lt;br /&gt;&lt;br /&gt;&lt;i&gt;delegate&lt;/i&gt; (optional_signature) { // method body - code }&lt;br /&gt;&lt;br /&gt;It is important to mention that the signature of the anonymous method must match with the delegate signature (this is how delegates basically work) being replaced. The return type and input parameter list must be the same. &lt;br /&gt;&lt;br /&gt;Let us see a simple example of using anonymous methods. Delegates play a de-facto role in events-based programming.  Consider the following code for an event: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;protected void Page_Load (object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;    Button1.Click += new EventHandler (Button1_Click);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;protected void Button1_Click (object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;    // implementation&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;Using anonymous method we can re-write the above as following:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Listing 7&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;protected void Page_Load (object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;    Button1.Click += delegate (object sender1, EventArgs s) { /* implementation */ };&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;In the code above, the EventHandler delegate has been replaced by an anonymous method. If we use ILSADM tool to view the assembly, you will find a new private method with matching signature as illustrated in figure 2. Under the hood, it is this method (&lt;Page_Load&gt;b__0) which is invoked by the compiler:&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Fig 2&lt;/b&gt;&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_a0lOQELDZCg/ScSZ_15fRbI/AAAAAAAAAAk/8GovrUwL9OQ/s1600-h/anonymous-wt-method.JPG"&gt;&lt;img style="float:none; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 320px; height: 160px;" src="http://1.bp.blogspot.com/_a0lOQELDZCg/ScSZ_15fRbI/AAAAAAAAAAk/8GovrUwL9OQ/s320/anonymous-wt-method.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5315542782283040178" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;An anonymous method can be declared within a static or an instance method. This also determines the type of the anonymous method, though private. Let us see another example where we actually declare a delegate. This anonymous method will perform some (complex :-) computation:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Listing 8&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;public delegate int MathDelegate (int n1, int n2, int n3); // declare delegate&lt;br /&gt;&lt;br /&gt;protected void Button1_Click (object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;    int result;&lt;br /&gt;&lt;br /&gt;    MathDelegate mathdel = delegate (int num1, int num2, int num3) /* anonymous type */&lt;br /&gt;                                        {&lt;br /&gt;                                            return (((num1 * num2) / num3) + 50); // any calculation&lt;br /&gt;                                        };&lt;br /&gt;&lt;br /&gt;    result              = (int) mathdel (10, 10, 2); // invoke delegate and cast reture-value&lt;br /&gt;    TextBox1.Text = result.ToString ();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;Usually for the above code to work, the delegate needs to reference a method with matching signature. However, in the above code, an anonymous method is defined inline to perform the calculation. Under the hood, again a private method is declared which is invoked by the compiler. &lt;br /&gt;&lt;br /&gt;The above is a trivial example; however anonymous methods can be useful in many scenarios such as collections and custom classes. Let us see an example of using an anonymous method within a collection. We first define a custom (my favorite :-) Fruit class: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;public class Fruit&lt;br /&gt;{&lt;br /&gt;    public Fruit (string n, string d)&lt;br /&gt;    {&lt;br /&gt;        FruitName        = n;&lt;br /&gt;        FruitDescription = d;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    // automatic-property&lt;br /&gt;    public string FruitName&lt;br /&gt;    {   get; set;   }&lt;br /&gt;    &lt;br /&gt;    // automatic-property&lt;br /&gt;    public string FruitDescription&lt;br /&gt;    {   get; set;   }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;Next we define a generic collection of type Fruit. This collection will let us find a particular fruit using an anonymous method:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Listing 9&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;protected void Button1_Click (object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;    string fruitName    = "kiwi";&lt;br /&gt;&lt;br /&gt;    List&amp;lt;Fruit&amp;gt; fruits  = new List&amp;lt;Fruit&amp;gt; ();&lt;br /&gt;&lt;br /&gt;    Fruit f1 = new Fruit ("mango", "A tropical fruit"); &lt;br /&gt;    Fruit f2 = new Fruit ("apple", "Have an apple a day"); &lt;br /&gt;    Fruit f3 = new Fruit ("kiwi", "Good for health");&lt;br /&gt;&lt;br /&gt;    fruits.Add (f1);&lt;br /&gt;    fruits.Add (f3);&lt;br /&gt;    fruits.Add (f2);&lt;br /&gt;&lt;br /&gt;    // using anonymous method&lt;br /&gt;    Fruit searchFruit = fruits.Find (delegate (Fruit f)&lt;br /&gt;                                        {&lt;br /&gt;                                            return f.FruitName == fruitName; // out of scope&lt;br /&gt;                                        });&lt;br /&gt;&lt;br /&gt;    if (searchFruit != null)&lt;br /&gt;    {&lt;br /&gt;        txtname.Text        = searchFruit.FruitName;&lt;br /&gt;        txtdescription.Text = searchFruit.FruitDescription;&lt;br /&gt;    }&lt;br /&gt;    else&lt;br /&gt;    {&lt;br /&gt;        Label1.Text = "Fruit not found...";&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;The above example has a few points to note. First, the &lt;i&gt;Find&lt;/i&gt; method expects a parameter of type &lt;i&gt;Predicate&lt;T&gt;&lt;/i&gt;. This parameter represents a delegate (a boolean expression) used by generic lists to filter and search an element. In the above code, the delegate gap is filled by an anonymous method. &lt;br /&gt;&lt;br /&gt;Second, if you watch closely, the anonymous method accesses a local variable (fruitName) which is in the scope of the outer method. How this works is pretty interesting. Earlier in Figure 2 we saw that the compiler generated a method for an anonymous method. But for a variable outside the scope of the anonymous method, the compiler generates a class. The generated method and variable are members of this class. When the anonymous method is invoked, the compiler creates and invokes an instance of this class. All the local variables maintain their state across calls made by the same instance. Figure 3 illustrates this concept: &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Fig 3&lt;/b&gt;&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_a0lOQELDZCg/ScSZ_7KqNnI/AAAAAAAAAAs/V9NtEFnabq0/s1600-h/anonymous-wt-class.JPG"&gt;&lt;img style="float:none; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 320px; height: 260px;" src="http://4.bp.blogspot.com/_a0lOQELDZCg/ScSZ_7KqNnI/AAAAAAAAAAs/V9NtEFnabq0/s320/anonymous-wt-class.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5315542783697237618" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;It is also important to note that an anonymous method cannot access &lt;i&gt;ref&lt;/i&gt; or &lt;i&gt;out&lt;/i&gt; variables of the outer method.&lt;br /&gt;&lt;br /&gt;Returning back to Lambda Expressions, they offer a convenient way to write anonymous methods. Using lambda expressions, we can omit much of the syntactical requirement of an anonymous method. For example, using lambda expression, listing 7 can be re-written as: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;protected void Page_Load (object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;    Button1.Click += (object s, EventArgs ea) =&amp;gt; { // implementation }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;To understand how the above works, you should know that a lambda expression offers the following liberty to developers:&lt;br /&gt;&lt;br /&gt;1. The &lt;i&gt;delegate&lt;/i&gt; keyword is not required.&lt;br /&gt;2. For a single statement, braces can be avoided. We use the lambda operator =&gt; (pronounced as goes to) in place of braces. The left side of this operator represents the input parameters while the right side is the expression block.&lt;br /&gt;3. The &lt;i&gt;return&lt;/i&gt; keyword is not required.&lt;br /&gt;4. Since C# 3.0 supports type inference, it is perfectly alright to drop the type definition for variables and let the compiler infer it (a very strong feature of lambda expressions).&lt;br /&gt;&lt;br /&gt;Using the above features, let us rewrite listing 8 as following: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;public delegate int MathDelegate (int n1, int n2, int n3); // declare delegate&lt;br /&gt;&lt;br /&gt;protected void Button1_Click(object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;    int result;&lt;br /&gt;&lt;br /&gt;    MathDelegate mathdel  = (num1, num2, num3) =&amp;gt;&lt;br /&gt;                            (((num1 * num2) / num3) + 50); // lambda-expression&lt;br /&gt;&lt;br /&gt;    result = (int) mathdel (10, 10, 2); // invoke delegate and cast reture-value&lt;br /&gt;    TextBox1.Text = result.ToString ();&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;Clearly, the above is a neat and concise expression written using lambda expression. The delegate and return keyword are not omitted. Similarly braces have been avoided and the compiler infers the data type of the input parameters. The same applies to the code in listing 9.&lt;br /&gt;&lt;br /&gt;To use a lambda expression, we need a delegate. .NET 3.5 facilitates us with two built-in generic delegate types, &lt;i&gt;Func&lt;/i&gt; and &lt;i&gt;Action&lt;/i&gt;, so that we don’t have to define our own delegates. The former returns a value while the later does not. In a &lt;i&gt;Func&lt;/i&gt; delegate, the last parameter represents the return type. It has the following overloads:&lt;br /&gt;&lt;br /&gt;public delegate TResult Func&amp;lt;TResult&amp;gt; ()&lt;br /&gt;public delegate TResult Func&amp;lt;T, TResult&amp;gt; (T t)&lt;br /&gt;public delegate TResult Func&amp;lt;T1, T2, TResult&amp;gt; (T1 t1, T2 t2)&lt;br /&gt;public delegate TResult Func&amp;lt;T1, T2, T3, TResult&amp;gt; (T1 t1, T2 t2, T3 t3)&lt;br /&gt;public delegate TResult Func&amp;lt;T1, T2, T3, T4, TResult&amp;gt; (T1 t1,T2 t2, T3 t3, T4 t4)&lt;br /&gt;&lt;br /&gt;Similarly, an &lt;i&gt;Action&lt;/i&gt; delegate accepts input parameter(s) but has a return type of void. It has the following overloads:&lt;br /&gt;&lt;br /&gt;public delegate void Action();&lt;br /&gt;public delegate void Action&amp;lt;T&amp;gt; (T t1);&lt;br /&gt;public delegate void Action&amp;lt;T1, T2&amp;gt; (T1 t1, T2 t2);&lt;br /&gt;public delegate void Action&amp;lt;T1, T2, T3&amp;gt; (T1 t1, T2 t2, T3 t3);&lt;br /&gt;public delegate void Action&amp;lt;T1, T2, T3, T4&amp;gt; (T1 t1, T2 t2, T3 t3, T4 t4);&lt;br /&gt;&lt;br /&gt;To help you understand the above, let me give you a simple example of using the &lt;i&gt;Func&lt;/i&gt; delegate with three parameters. The &lt;i&gt;Action&lt;/i&gt; delegate is no different (except with no return type).&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Listing 10&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;Func&amp;lt;string, string, string /*return type */&amp;gt; GreetPerson = (message, person) =&amp;gt; &lt;br /&gt;  message + " " + person;&lt;br /&gt;&lt;br /&gt;protected void Button1_Click (object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt; TextBox1.Text = GreetPerson (“Hello”, “Scott”);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;I am sure you can evaluate the above code with ease. Func&lt;string, string, string&gt; defines a delegate which accepts two input parameter (message, person) of type string and the last parameter, also a string, as the return type. Clearly, it has simplified the process of defining a delegate. Otherwise we had to define a delegate with matching signature. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Summary&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;In this post, we looked at different C# language features which make up LINQ. The yield statement lets us implement enumerators without implementing any enumerator interface. Also, the yield maintains state between calls. This is possible since the compiler maintains a state engine.&lt;br /&gt;&lt;br /&gt;Extension methods enable us to add functionality to existing types. The types can be primitive or custom. Extension methods are static methods but are invoked like instance methods. These methods are defined in a separate static class. The first input parameter is preceded by ‘this’ keyword which makes it an extension method. This parameter also defines the type on which the extension method will operate. &lt;br /&gt;&lt;br /&gt;The var keyword is used to declare implicitly typed local variables. These are strongly typed variables and their types cannot be changed later on. The compiler is responsible for determining the type at runtime. We can either explicitly assign a value or return a value from a method to a ‘var’ variable. These variables must be instantiated with a value so that the compiler can infer the type at runtime.&lt;br /&gt;&lt;br /&gt;Anonymous Types facilitate us to create types without actually declaring it. The type is inferred by the compiler at runtime. Anonymous types in turn use a feature known as ‘object initialization’ to work. Object initialization lets us initialize properties without invoking the constructor, when creating objects. &lt;br /&gt;&lt;br /&gt;Anonymous methods allow us to use a piece of code inline without defining a separate method. The code is declared and used at the same place. Anonymous methods can be used where a delegate is anticipated. An anonymous method is defined using the &lt;i&gt;delegate&lt;/i&gt; keyword followed by an optional list of parameters (within parenthesis) and the body of the method. If an anonymous method doesn’t have any parameters, parenthesis can be omitted. The signature of anonymous method must match with the signature of the delegate being replaced.&lt;br /&gt;&lt;br /&gt;Lambda expressions offer a concise way to write anonymous methods. Using lambda expression, we can avoid the extra syntactical requirement of an anonymous method. We can omit the delegate and return keyword. Also, the compiler can infer the data type of the input parameters. To use a lambda expression, a delegate is required. .NET framework has two built in function, ‘Action’ and ‘Func’ respectively, which help us use a lambda expression without actually defining it.&lt;br /&gt;&lt;br /&gt;With this we come to the end of this post. To concentrate more on LINQ, I had to sum up all the above concepts in two posts otherwise each feature is worth a separate post. In the next post we will start looking at LINQ Syntax and how it can be leveraged into our code. So stay tuned for more…&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/834688215084300455-2669745495563410270?l=dotnetpost.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetpost.blogspot.com/feeds/2669745495563410270/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetpost.blogspot.com/2009/03/linq-explained-part-3.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/2669745495563410270'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/2669745495563410270'/><link rel='alternate' type='text/html' href='http://dotnetpost.blogspot.com/2009/03/linq-explained-part-3.html' title='LINQ Explained – Part 3'/><author><name>Kashif Ahmad</name><uri>http://www.blogger.com/profile/02151423871584093787</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_a0lOQELDZCg/ScSZ_U23WbI/AAAAAAAAAAc/y8kKlzdhO98/s72-c/Enumerator.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-834688215084300455.post-138347714587376156</id><published>2009-02-10T02:10:00.000-08:00</published><updated>2009-03-21T06:55:45.577-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='General'/><title type='text'>NHibernate Screencast Series</title><content type='html'>&lt;br&gt;&lt;br /&gt;I have found an excellent series of NHibernate screencasts and thought of sharing it with you. The screencasts are located at &lt;a href="http://www.summerofnhibernate.com"&gt;SummerOfNHibernate&lt;/a&gt;. Hope you find them useful.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/834688215084300455-138347714587376156?l=dotnetpost.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetpost.blogspot.com/feeds/138347714587376156/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetpost.blogspot.com/2009/02/nhibernate-screencast-series.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/138347714587376156'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/138347714587376156'/><link rel='alternate' type='text/html' href='http://dotnetpost.blogspot.com/2009/02/nhibernate-screencast-series.html' title='NHibernate Screencast Series'/><author><name>Kashif Ahmad</name><uri>http://www.blogger.com/profile/02151423871584093787</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-834688215084300455.post-5790731388075864112</id><published>2009-02-05T01:46:00.000-08:00</published><updated>2009-02-05T08:51:52.007-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='AJAX'/><title type='text'>How Microsoft AJAX Client Library is Organized</title><content type='html'>&lt;br&gt;&lt;span style="font-family:Verdana;"&gt;Recently I ran into confusion about how &lt;b&gt;Microsoft Ajax Client Library&lt;/b&gt; is organized. After having my head clear on it, I decided to share my understanding with you. In this post, we will see how the client library is organized across different JavaScript files and Namespaces.&lt;br /&gt;&lt;br /&gt;First, the Microsoft Ajax Client Library is organized in JavaScript files. The following three JavaScript files make up the client library:&lt;br /&gt;&lt;br /&gt;1. MicrosoftAjax.js&lt;br /&gt;2. MicrosoftAjaxTimer.js&lt;br /&gt;3. MicrosoftAjaxWebForms.js&lt;br /&gt;&lt;br /&gt;These JavaScript files are embedded as resources in the Sytem.Web.Extensions assembly. This assembly is installed in the Global Assembly Cache (GAC) by the Microsoft Ajax Extension installer. As you know that every Microsoft ASP.NET Ajax application has one ScriptManager control. It’s this ScriptManager which is actually responsible for loading the JavaScript files in the asp.net page. So we must include the ScriptManager control to enable Ajax functionality in our applications.&lt;br /&gt;&lt;br /&gt;Second, the JavaScript files (library) consist of many client classes which are then organized into client namespaces. These namespaces include:&lt;br /&gt;&lt;br /&gt;1. Sys&lt;br /&gt;2. Sys.Net&lt;br /&gt;3. Sys.UI&lt;br /&gt;4. Sys.Services&lt;br /&gt;5. Sys.Serialization&lt;br /&gt;6. Sys.WebForms &lt;br /&gt;&lt;br /&gt;My confusion was about the difference between the JavaScript files and the Namespaces (client classes). Are these separate or do they complement each other. So here is what I understood after talking to the experts.&lt;br /&gt;&lt;br /&gt;The JavaScript files (MicrosoftAjax, MicrosoftAjaxTimer, MicrosoftAjaxWebForms) represent the &lt;i&gt;physical organization (features split in different files)&lt;/i&gt; whereas the Namespaces (Sys, Sys.Net, Sys.UI etc) correspond to the &lt;i&gt;logical grouping (client classes into namespaces)&lt;/i&gt; of the client library. The namespaces span across the JavaScript files (and so do the client classes). When the JavaScript files are loaded in the web page, the &lt;b&gt;entire client library (namespaces and client classes)&lt;/b&gt; gets loaded. &lt;br /&gt;&lt;br /&gt;One point worth noting is that the JavaScript files come in two versions – the &lt;i&gt;debug&lt;/i&gt; and &lt;i&gt;release&lt;/i&gt; version. The ScriptManager always loads the release version (a stripped down version with no comments and debugging tricks) in the asp.net page unless specified. If we want to load a debug version of the script files, we can do so by using the following syntax: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;&amp;lt;asp:ScriptManager ID=”ScriptManager1” runat=”server”&amp;gt;&lt;br /&gt; &amp;lt;Scripts&amp;gt;&lt;br /&gt;  &amp;lt;asp:ScriptReference Path=”~/ScriptLibrary/ScriptFile” ScriptMode=”Debug”/&amp;gt;&lt;br /&gt; &amp;lt;/Scripts&amp;gt;&lt;br /&gt;&amp;lt;/ScriptManager&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Summary&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;&lt;br /&gt;In this post, we saw how Microsoft Ajax Client Library is organized. The JavaScript files represent the physical organization of the library. The namespaces represent the logical arrangement of client classes. The JavaScript files have many client classes and these classes are arranged under the different namespaces. The namespace (hence client classes) span across the JavaScript files. &lt;br /&gt;&lt;br /&gt;I hope this post was useful in removing any doubts regarding the arrangement of the Ajax Client Library. Stay tuned for more…&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/834688215084300455-5790731388075864112?l=dotnetpost.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetpost.blogspot.com/feeds/5790731388075864112/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetpost.blogspot.com/2009/02/how-microsoft-ajax-client-library-is.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/5790731388075864112'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/5790731388075864112'/><link rel='alternate' type='text/html' href='http://dotnetpost.blogspot.com/2009/02/how-microsoft-ajax-client-library-is.html' title='How Microsoft AJAX Client Library is Organized'/><author><name>Kashif Ahmad</name><uri>http://www.blogger.com/profile/02151423871584093787</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-834688215084300455.post-4572833945279438927</id><published>2008-12-17T04:51:00.000-08:00</published><updated>2009-02-27T10:36:07.182-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MVC'/><title type='text'>Understanding ASP.NET MVC Framework</title><content type='html'>&lt;span style="font-family:Verdana;"&gt;This post will provide you an architectural overview of the ASP.NET MVC Framework. We will explore the underlying concepts which make up the ASP.NET MVC Framework. This post is not meant to getting you started with creating a MVC Application. It rather gives you the background knowledge needed to work with a MVC application. Creating a MVC application will be the topic of a future post.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;&lt;br /&gt;Introduction&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;&lt;br /&gt;The ASP.NET MVC Framework helps developers implement the Model-View-Controller pattern. The framework provides a clean separation of concerns in a web application. This gives the developers better control over the applications which are easy to maintain. &lt;br /&gt;&lt;br /&gt;The MVC Framework is a shift of thinking from the traditional ASP.NET web applications. In an ASP.NET application, a URL points to a resource or content such as a web page or image which is served by the server. The content must exist before being served else an exception may be thrown. On the other hand, in a MVC application, the URL request is handled by a piece of code. This means that every request is handled by a method of a particular class. So there is basic difference between the two programming models. The prior serves existing contents for a request whereas the later runs a piece of code for a request. &lt;br /&gt;&lt;br /&gt;Before we proceed, let’s look at Fig 1. This figure shows the solution when we create an ASP.NET MVC Application using Visual Studio. It has different sub folders including Models, Views and Controllers. A discussion of these sub folders will follow shortly. If you expand the References folder, you will find a reference added to System.Web.Mvc nampspace which is required to work with a MVC application. &lt;/span&gt;&lt;br/&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_a0lOQELDZCg/SUj2tiJII9I/AAAAAAAAAAM/xMlfnMcIG2s/s1600-h/DirectoryStructure.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 243px; height: 320px;" src="http://1.bp.blogspot.com/_a0lOQELDZCg/SUj2tiJII9I/AAAAAAAAAAM/xMlfnMcIG2s/s320/DirectoryStructure.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5280741825211540434" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;strong&gt;Fig 1&lt;/strong&gt;&lt;br/&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;&lt;br /&gt;Controllers&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;In a MVC application, a Controller is responsible for handling a request. Each URL request is served by a particular controller. It acts as a bridge between the requests and the application. &lt;br /&gt;&lt;br /&gt;In Fig 1, you can see a Controllers folder. All controllers are added under this folder. The controller name must be suffixed with the word ‘Controller’. For example, to create a Product controller, we name it as ProductController. If a user enters the URL /Product, it gets mapped to /ProductController. Even if a controller with the name Product exists, it will not respond to a user request. This is the default behavior for an ASP.NET MVC Application.&lt;br /&gt;&lt;br /&gt;A controller is just a C# or VB class. This class is driven from System.Web.Mvc.Controller base class. Listing 1 is an example of a ProductController class:&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;Listing 1&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Web.Mvc;&lt;br /&gt;&lt;br /&gt;namespace MVCDemo.Controllers&lt;br /&gt;{&lt;br /&gt;     public class ProductController : Controller&lt;br /&gt;     {&lt;br /&gt;                   public ActionResult Index ()&lt;br /&gt;                   {&lt;br /&gt;                              // Add action logic here&lt;br /&gt;                              throw new NotImplementedException();&lt;br /&gt;                     }&lt;br /&gt;          }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;A controller consists of Controller Actions. Controller Actions or simply actions are the public methods in a controller. Each request is processed by a controller action in a controller. For example, if a user enters the URL /Product/Index, the Index method in the ProductController class is invoked. Any method which is added as a public method to a controller becomes a controller action. Controller actions have certain properties which include:&lt;br /&gt;&lt;br /&gt;• They cannot be overloaded&lt;br /&gt;• All actions must be public&lt;br /&gt;• They cannot be static&lt;br /&gt;• An action returns an ActionResult&lt;br /&gt;&lt;br /&gt;The outcome (return type) of a controller action is an Action Result. There are different types of action result, all of which are driven from the base class ActionResult. These action results include:&lt;br /&gt;&lt;br /&gt;ViewResult: Returns HTML markup or content to the browser&lt;br /&gt;EmptyResult – Represents no result&lt;br /&gt;RedirectResult – Redirect to a new URL&lt;br /&gt;RedirectToRouteResult – Redirects to a new controller action&lt;br /&gt;JsonResult – Returns JavaScript Object Notation result for AJAX applications &lt;br /&gt;ContentResult – Returns a text result&lt;br /&gt;&lt;br /&gt;We are not required to return a particular type of action result directly i.e. we don’t return a ViewResult or JsonResult. Rather we use one of the methods provided by the base class Controller. The different base class methods are:&lt;br /&gt;&lt;br /&gt;1.   View – Returns a ViewResult action result. &lt;br /&gt;2.   Redirect – Returns a RedirectResult action result. &lt;br /&gt;3.   RedirectToAction – Returns a RedirectToRouteResult action result. &lt;br /&gt;4.   RedirectToRoute – Returns a RedirectToRouteResult action result. &lt;br /&gt;5.   Json – Returns a JsonResult action result. &lt;br /&gt;6.   Content – Returns a ContentResult action result. &lt;br /&gt;&lt;br /&gt;Listing 2 shows controller actions return different types of action results:&lt;br /&gt;&lt;br /&gt;Listing 2&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Web.Mvc;&lt;br /&gt;&lt;br /&gt;namespace MVCDemo.Controllers&lt;br /&gt;{&lt;br /&gt;          public class ProductController : Controller&lt;br /&gt;          {&lt;br /&gt;                    // 1 – return ViewResult()&lt;br /&gt;                    public ActionResult Index ()&lt;br /&gt;                    {&lt;br /&gt;                               return View ();&lt;br /&gt;                     }&lt;br /&gt;&lt;br /&gt;                    // 2 – redirect to another controller action – RedirectToRouteResult()&lt;br /&gt;                    public ActionResult RedirectMe ()&lt;br /&gt;                    {&lt;br /&gt;                               return RedirectToAction ("Index");&lt;br /&gt;                    }&lt;br /&gt;&lt;br /&gt;                    // 3 – return content – ContentResult()&lt;br /&gt;                    public ContentResult ReturnContent ()&lt;br /&gt;                    {&lt;br /&gt;                               return Content ("Just a simple string...");&lt;br /&gt;                    }&lt;br /&gt;&lt;br /&gt;                    public DateTime ReturnDate()&lt;br /&gt;                    {&lt;br /&gt;                                return DateTime.Now;&lt;br /&gt;                    }&lt;br /&gt;           }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;The first controller action (Index) returns a view by calling the base class method. The view returned should correspond to name of the controller action. So a view named Index.aspx is returned to the browser. The location of Index.aspx will come up in the next section.&lt;br /&gt;&lt;br /&gt;The base class method RedirectToAction in the second controller action (RedirectMe) redirects the request to the first controller action. The request is redirected to Index.aspx.&lt;br /&gt;&lt;br /&gt;Another special type of action result is the ContentResult which returns plain text. Using the base class method Content in the third controller action (ReturnContent), a string is returned to the browser. The source of the page will show you a simple text message with no HTML embedded in it.&lt;br /&gt;&lt;br /&gt;If a controller action does not return an action result, it is also treated as ContentResult. The MVC framework calls the ToString () method on the result and wraps it in a ContentResult action result. The fourth action controller will again return current DateTime as a string. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;&lt;br /&gt;Views&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;As mentioned, in a MVC application, a request does not map to a page or resource. Rather all requests are handled by actions in a controller. An action can return different types of action results including a View. A view is closest to an asp.net web page since it renders HTML markup and content. Listing 2 has one of the following actions: &lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;public ActionResult Index ()&lt;br /&gt;{&lt;br /&gt;           return View ();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;This action returns a view. The action is invoked by typing in /Product/Index which returns a page Index.aspx from the following location:&lt;br /&gt;&lt;br /&gt;\Views\Product\Index.aspx&lt;br /&gt;&lt;br /&gt;The location of a view is inferred from the name of the Controller and name of the Controller Action. If you look at Fig 1, you will find a Views folder. All views are under this folder. For the above URL, the Views folder must have a sub folder named after the Controller (Product). The sub folder in turn must have a view page named after the controller action (Index in this case). So a view page Index.aspx is returned to the browser. Figure 2 makes it clear: &lt;/span&gt;&lt;br/&gt; &lt;br/&gt;&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_a0lOQELDZCg/SUj3zSd8ReI/AAAAAAAAAAU/cLUhaaLnX2Y/s1600-h/Views.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 245px; height: 320px;" src="http://4.bp.blogspot.com/_a0lOQELDZCg/SUj3zSd8ReI/AAAAAAAAAAU/cLUhaaLnX2Y/s320/Views.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5280743023594718690" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;strong&gt;Fig 2&lt;/strong&gt;&lt;br/&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;We can also explicitly mention the name of the view when calling the return View () statement. For example, the statement ‘return View (“Index”)’ is equal to the statement ‘return View ()’.&lt;br /&gt;&lt;br /&gt;A View is an HTML document where scripts are written. Writing a view is a kind of a journey back to the Active Server Pages age. An ASP page does not have the notion of a code behind file. All validation, data handling and business logic code are written on the same page. We make extensive use of Response.Write in traditional ASP application. A script written in a View is somewhat similar to an ASP code. &lt;br /&gt;&lt;br /&gt;In a view, script delimiters &amp;lt;% and %&amp;gt; mark the beginning and end of a script. We can then use the Response.Write method to emit some data. For example, the following line will write a string:&lt;br /&gt;&lt;br /&gt;&amp;lt;% Response.Write ("This is a view script");%&amp;gt;  &lt;br /&gt;&lt;br /&gt;In order to save coding time, we can also use the shortcut delimiter &amp;lt;%= %&amp;gt; in place of Response.Write. Listing 3 makes use of both delimiters:&lt;br /&gt;&lt;br /&gt;Listing 3&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;&amp;lt;%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Index.aspx.cs" &lt;br /&gt;                 Inherits="MVCDemo.Views.Home.Index" %&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&amp;gt; &lt;br /&gt;&amp;lt;html xmlns="http://www.w3.org/1999/xhtml" &amp;gt; &lt;br /&gt;    &lt;br /&gt;&amp;lt;head id="Index View" runat="server"&amp;gt; &lt;br /&gt;    &amp;lt;title&amp;gt;Index&amp;lt;/title&amp;gt; &lt;br /&gt;&amp;lt;/head&amp;gt; &lt;br /&gt;&lt;br /&gt;&amp;lt;body&amp;gt; &lt;br /&gt;    &amp;lt;div&amp;gt; &lt;br /&gt;        &amp;lt;% Response.Write ("MVC framework demo"); %&amp;gt;&lt;br /&gt;        &amp;lt;br /&amp;gt;&lt;br /&gt;        Date-Time: &amp;lt;%=DateTime.Now%&amp;gt;&lt;br /&gt;    &amp;lt;/div&amp;gt; &lt;br /&gt;&amp;lt;/body&amp;gt;    &lt;br /&gt;&amp;lt;/html&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;To facilitate the developers, HTML Helpers are used to add content to a view. HTML Helpers are methods that return a string (such as markup). This way we don’t have to type the HTML markup. These HTML helpers generate standard controls including TextBoxes, hyperlinks, dropdown lists etc. The helper methods are called using the HTML property of the view. The following snippet generates a simple Product entry form using HTML Helpers: &lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;&amp;lt;form method="post" action="/Product/Add"&amp;gt; &lt;br /&gt;          &amp;lt;label for="ProductName"&amp;gt;Product: &amp;lt;/label&amp;gt;&lt;br /&gt;          &amp;lt;%=Html.TextBox ("ProductName")%&amp;gt;&lt;br /&gt;          &amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;          &amp;lt;label for="Quantity"&amp;gt;Quantity: &amp;lt;/label&amp;gt;&lt;br /&gt;          &amp;lt;%=Html.TextBox ("Quantity")%&amp;gt;&lt;br /&gt;          &amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;          &amp;lt;label for="Available"&amp;gt; &amp;lt;/label&amp;gt;&lt;br /&gt;          &amp;lt;%=Html.CheckBox ("Available", "Available")%&amp;gt;&lt;br /&gt;          &amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;          &amp;lt;input type="submit" value="Add Product" /&amp;gt; &lt;br /&gt;&amp;lt;/form&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;Notice the use of the delimiters with HTML helper method. Since HTML Helper methods return a string, we need to use Response.Write or the shortcut delimiter &amp;lt;% %&amp;gt; to render the string (control markup) in the browser. For this reason, the above snippet has the Html.TextBox (…) helper method enclosed in a delimiter.&lt;br /&gt;&lt;br /&gt;Another interesting property of a view is the ViewData property. ViewData is used by controllers to pass data to a view. The ViewData works like a dictionary holding collections of key-value pairs. Let us look at an example: &lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;public ActionResult ProductDetails ()&lt;br /&gt;{&lt;br /&gt;          ViewData ["Info"] = "Available in stock";&lt;br /&gt;          return View ();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;In the above snippet, the action ProductDetails uses ViewData property to pass down the key ‘Info’ with a value ‘Available in stock’ to the view. This key can be used later in the view to retrieve the data with the following code:&lt;br /&gt;&lt;br /&gt;&amp;lt;%= ViewData ["Info "] %&amp;gt;&lt;br /&gt;&lt;br /&gt;A good use of the ViewData property would be to send database records or XML data to a view. The controller action can access the database and pass the data to the view. This also results in a clean separation of concerns where data access is separate from the view. Similarly an action can read a file and send its contents to the view. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;&lt;br /&gt;Models &lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;The controllers hold logic to handle incoming request and views represent the UI of a MVC application. Where does the business logic and data access code reside? This is where Models come into play. Models are responsible for hosting the business logic. They also hold data access components. For example, we can have DAL (Data Access Layer) classes, Entities or LINQ to SQL classes as models. In fig 1, you can see a Models folder. All data access classes must be placed under this folder.&lt;br /&gt;&lt;br /&gt;As a best practice, fat models and thin controllers are recommended. The controller should only be concerned with handling requests whereas the models should deal with business logic and data access code. Even if a controller is passing data to a view fetched from the model, it should be limited to making calls to the model. This also results in a clean separation of concerns in a MVC application. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;&lt;br /&gt;URL Routing&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;So how does a piece of code get executed when a request is made in a MVC application? This is where the URL Routing comes into play. URL Routing is a key feature of a MVC application. It is a mechanism through which a URL is mapped to a controller action. URL Routing is handled in the Web.Config and Global.asax file.&lt;br /&gt;&lt;br /&gt;The Global.asax handles the application lifecycle events. One of these events is the Application_Start event which is raised when an application starts. Listing 4 shows the Global.asax:&lt;br /&gt;&lt;br /&gt;Listing 4 – Global.asax&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;using System.Web.Mvc;&lt;br /&gt;using System.Web.Routing;&lt;br /&gt;&lt;br /&gt;namespace HelloMVC&lt;br /&gt;{&lt;br /&gt;           public class GlobalApplication : System.Web.HttpApplication&lt;br /&gt;           {&lt;br /&gt;                    public static void RegisterRoutes (RouteCollection routes)&lt;br /&gt;                    {&lt;br /&gt;                               routes.IgnoreRoute ("{resource}.axd/{*pathInfo}");&lt;br /&gt;                               &lt;br /&gt;                               routes.MapRoute (&lt;br /&gt;                                         "Default",  // Route name&lt;br /&gt;                                         "{controller}/{action}/{id}",  // URL with parameters&lt;br /&gt;                                         new { controller = "Home", action = "Index", id = "" }&lt;br /&gt;                                         // Parameter defaults&lt;br /&gt;                               );&lt;br /&gt;                    }&lt;br /&gt;&lt;br /&gt;                    protected void Application_Start ()&lt;br /&gt;                    {&lt;br /&gt;                              RegisterRoutes (RouteTable.Routes);&lt;br /&gt;                    }&lt;br /&gt;           }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;The Application_Start event calls the RegisterRoutes method. The RegisterRoutes method creates a route table. &lt;br /&gt;&lt;br /&gt;The default route table contains of a single route (Default). If you look at above listing, you can see that the Default route maps the first segment of a URL to a controller name, the second segment of a URL to a controller action, and the third segment to a parameter named id. This means that a request such as /Prodct/Add/20 will look for a controller Product with action Add and a parameter to add equal to 20.&lt;br /&gt;&lt;br /&gt;The Default route includes defaults for all three parameters. If you don’t supply a controller, then the controller parameter defaults to the value Home. If you don’t supply an action, the action parameter defaults to the value Index. Finally, if you don’t supply an id, the id parameter defaults to an empty string.&lt;br /&gt;&lt;br /&gt;Let us see a few examples of URL mapping. Suppose we enter a URL &lt;br /&gt;&lt;br /&gt;/Home/Index/2&lt;br /&gt;&lt;br /&gt;The parameters for this URL are:&lt;br /&gt;&lt;br /&gt;Controller = Home&lt;br /&gt;Action = Index&lt;br /&gt;Id = 2&lt;br /&gt;&lt;br /&gt;The code generated for these parameters is&lt;br /&gt;&lt;br /&gt;HomeController.Index (3)&lt;br /&gt;&lt;br /&gt;Similarly if the URL is&lt;br /&gt;&lt;br /&gt;/Product/Delete/19&lt;br /&gt;&lt;br /&gt;It is converted to:&lt;br /&gt;&lt;br /&gt;Controller = Product&lt;br /&gt;Action = Delete&lt;br /&gt;Id = 19&lt;br /&gt;&lt;br /&gt;Now the code generated is&lt;br /&gt;&lt;br /&gt;ProductController.Delete (19)&lt;br /&gt;&lt;br /&gt;The default route table is fine for a general MVC application. However, we can also create custom routes depending on our routing needs. For example, we are creating an Online Reporting System. This system helps user create and maintain reports. The reports are maintained on a date-by-date basis. The user is allowed to enter a URL like:&lt;br /&gt;&lt;br /&gt;/Files/06-19-2008&lt;br /&gt;&lt;br /&gt;To handle such request, let us edit Global.asax in listing 5 with our new route defined:&lt;br /&gt;&lt;br /&gt;Listing 5&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;using System.Web.Mvc;&lt;br /&gt;using System.Web.Routing;&lt;br /&gt;&lt;br /&gt;namespace MVCDemo&lt;br /&gt;{&lt;br /&gt;    public class GlobalApplication : System.Web.HttpApplication&lt;br /&gt;    {&lt;br /&gt;        public static void RegisterRoutes(RouteCollection routes)&lt;br /&gt;        {&lt;br /&gt;            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");&lt;br /&gt;&lt;br /&gt;            routes.MapRoute(&lt;br /&gt;                "OnlineReporting",&lt;br /&gt;                "Files/{DateModified}",&lt;br /&gt;                new {controller = "Files", action = "Modified"}&lt;br /&gt;            );&lt;br /&gt;&lt;br /&gt;            routes.MapRoute(&lt;br /&gt;                "Default",  // Route name&lt;br /&gt;                "{controller}/{action}/{id}", // URL with parameters&lt;br /&gt;                new { controller = "Home", action = "Index", id = "" }&lt;br /&gt;                // Parameter defaults&lt;br /&gt;            );&lt;br /&gt;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        protected void Application_Start()&lt;br /&gt;        {&lt;br /&gt;            RegisterRoutes (RouteTable.Routes);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;The order in which routes are added matters. The OnlineReporting route is added before the default blog. If it is placed after the default route, the default route will always get called before the custom route. Hence our request won’t be handled resulting in an exception.&lt;br /&gt;&lt;br /&gt;For the OnlineReport route to work, we must have a Files controller and a Modified action controller. When the Modified method is invoked, DateModified is passed in as parameter. So the code generated is &lt;br /&gt;&lt;br /&gt;Files.Modified (DateModified)&lt;br /&gt;Since this method accepts datetime as parameter, the MVC framework converts the parameter to a datetime value. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;&lt;br /&gt;Summary&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;In this blog entry, we looked at the architecture of an ASP.NET MVC application. Unlike asp.net applications, a request is handled by a Controller. A Controller is class which can have public methods known as Controller Actions. The request invokes the controller action of a controller. The result of a controller action is of type Action Result. There are different types of action results. We can use methods of the base class Controller to return different types of results.&lt;br /&gt;&lt;br /&gt;A view is similar to an asp.net page which renders html markup to a browser. In a view, delimiters &amp;lt;% %&amp;gt; mark the start and end of a script. To render markup on a page, HTML Helper methods are available in a view. These helper methods rid us of writing markup code by rendering controls on a page. The ViewData property of a view is used to pass down information from a controller to a view.&lt;br /&gt;&lt;br /&gt;Models take care of business logic and data access in a MVC application. The models can consist of DALs, Entities and LINQ to SQL classes. To maintain clean separation of concern, we should favor fat models and thin controllers.&lt;br /&gt;&lt;br /&gt;URL Routing is another important feature of a MVC application. It handles and supports user friendly URLs. To handle URLs, a route table is created in the Global.asax file using the Applicatin_Start event handler. This table defines the parameters for a URL which includes the controller, the controller action and any id passed to the controller action. Finally we can also setup custom routes to handle any special routing need.&lt;br /&gt;&lt;br /&gt;I hope this post has given you sufficient insight into ASP.NET MVC architecture. In a future post, I will talk about creating and working with a MVC application. So stay tuned…&lt;/span&gt;&lt;br/&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/834688215084300455-4572833945279438927?l=dotnetpost.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetpost.blogspot.com/feeds/4572833945279438927/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetpost.blogspot.com/2008/12/understanding-aspnet-mvc-framework.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/4572833945279438927'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/4572833945279438927'/><link rel='alternate' type='text/html' href='http://dotnetpost.blogspot.com/2008/12/understanding-aspnet-mvc-framework.html' title='Understanding ASP.NET MVC Framework'/><author><name>Kashif Ahmad</name><uri>http://www.blogger.com/profile/02151423871584093787</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_a0lOQELDZCg/SUj2tiJII9I/AAAAAAAAAAM/xMlfnMcIG2s/s72-c/DirectoryStructure.JPG' height='72' width='72'/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-834688215084300455.post-926350616212309409</id><published>2008-12-11T11:12:00.000-08:00</published><updated>2009-02-24T22:53:06.267-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='LINQ'/><title type='text'>LINQ Explained– Part 2</title><content type='html'>&lt;span style="font-family:Verdana;"&gt;This is the second part of my on going series on LINQ. In the &lt;a href="http://dotnetpost.blogspot.com/2008/10/linq-explained-part-1.html"&gt;first&lt;/a&gt; installment, we had an overview of LINQ. In this post, we will look at some of the underlying concepts which are important to understand to work with LINQ. Though you are not required to master them but an understanding of these concepts gives you the extra level of confidence to work with LINQ. (Note: I will use C# as language of preference in this series). &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;LINQ and C# Language&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;LINQ works with C# 3.0 and Visual Basic 9.0. It relies heavily on the features provided by these languages. Although these features may be used separately, they are fundamental to the working of LINQ. Some of these features were delivered with C# 1.x and 2.0 – the predecessor to C# 3.0. The following sections describe these features in more detail. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Generics&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;Let us look at a simple example of comparing two numbers. The following method accepts two integers as argument, compares them and returns the result: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;private int Compare (int x, int y)&lt;br /&gt;{&lt;br /&gt; return x &amp;lt; y ? x : y;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;This code works fine for comparing two integers. But suppose we wanted to compare two floating values or even two strings. For this purpose, either we change the method signature to accept the respective types or we end up writing entirely new methods for each type. But as developers, we would be inclined towards using a generalized method to perform the same function irrespective of the argument types.&lt;br /&gt;&lt;br /&gt;One solution to the above problem is to accept object as arguments. In C#, every type is driven from the base type &lt;i&gt;object&lt;/i&gt; so it can be cast to and back from the object type. We can rewrite the above method as following: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;private object Compare (object x, object y)&lt;br /&gt;{&lt;br /&gt;           // comparison logic goes here&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;The above method now accepts object as argument. This makes the method more generalized but with some shortcomings. First of all, C# is a type-safe language, that is, objects have associated type and only operations defined by the associated types can be performed on an object. A comparison operator such as ‘&amp;lt;’ will not operate on the reference type object. Thus a conversion of &lt;i&gt;object&lt;/i&gt; to a value type is required before the comparison is performed. This means to use a type, explicit casting required. For example, to convert to an integer, we write the following code:&lt;br /&gt;&lt;br /&gt;int i = (int) x;&lt;br /&gt;int j = (int) y;&lt;br /&gt;&lt;br /&gt;Similarly, to check for string, we perform the following casting:&lt;br /&gt;&lt;br /&gt;string str1 = (string) x;&lt;br /&gt;string str2 = (string) y;&lt;br /&gt;&lt;br /&gt;Second, when a value type is converted to a reference type (boxing), it involves an overhead. A conversion back to the value type from a reference type (unboxing) also involves an overhead. As a result of boxing and unboxing, there is a performance hit for an application. This is further magnified when Collections are used. Collections such as Stack, Queue, ArrayList operate on &lt;i&gt;object&lt;/i&gt; type only. When an element is added to a collection, boxing takes places. Similarly, when a value is retrieved from the collection, unboxing is done. This means every time an element is added or retrieved from a collection, a performance overhead is involved.&lt;br /&gt;&lt;br /&gt;The above issues can be catered through Generics. A C# 2.0 language feature, Generics introduced the concept of &lt;i&gt;type parameters&lt;/i&gt;. Classes and methods can defer the definition of one or more type until runtime. With Generics, there is one implementation for all types. The type definition is performed when the method is invoked or an object is instantiated. Let us redefine our Compare method using Generics: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;private T Compare &amp;lt;T&amp;gt; (T x, T y) where T : IComparable &amp;lt;T&amp;gt;&lt;br /&gt;{&lt;br /&gt;           return x.CompareTo (y) &lt; 0 ? x : y;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;A placeholder &amp;lt;T&amp;gt; appended to the method name points to a generic method. The placeholder &amp;lt;T&amp;gt; represents the type parameter to be provided when this method is used. The same placeholder is used for the input and output parameters. Note that since &amp;lt;T&amp;gt; is just a placeholder (and not a type), the CompareTo method cannot operate on it directly. For this reason, &amp;lt;T&amp;gt; implements the IComparable interface. We will look at the ‘where’ constraint shortly. For now we can use the above method for the comparison of different types as following:&lt;br /&gt;&lt;br /&gt;int a = 20, b = 19;&lt;br /&gt;int c = Compare &amp;lt;int&amp;gt; (a, b);&lt;br /&gt;&lt;br /&gt;string str1 = "Zzzz", str2 = "Aaaa";&lt;br /&gt;string str3 = Compare &amp;lt;string&amp;gt; (str1, str2);&lt;br /&gt;&lt;br /&gt;Notice that there is no explicit casting required for the arguments. The method is invoked with the type parameter inplace of the placeholder and that’s it. The CLR is responsible for handling the rest.&lt;br /&gt;&lt;br /&gt;The Generic concept also applies to classes and structures. Let us look at a Generic class: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;public class UserAuthentication &amp;lt;T&amp;gt;&lt;br /&gt;{&lt;br /&gt; private T myPassword;&lt;br /&gt;             private string myUserID;&lt;br /&gt;&lt;br /&gt;             public T Password&lt;br /&gt;     {&lt;br /&gt;  get { return myPassword; }&lt;br /&gt;                          set { myPassword = value; }&lt;br /&gt;     }&lt;br /&gt;&lt;br /&gt;     public string UserID&lt;br /&gt;     {&lt;br /&gt;          get { return      myUserID; }&lt;br /&gt;          set { myUserID    = value; }&lt;br /&gt;     }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;The above class creates a token for user authentication. Notice the placeholder &amp;lt;T&amp;gt; defined next to the class name. The password field is of the same type parameter. Similarly the Password property has a returns type of &amp;lt;T&amp;gt;. We can instantiated the above class with following code: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;UserAuthentication &amp;lt;string&amp;gt; userAuth;&lt;br /&gt;        &lt;br /&gt;userAuth                 = new UserAuthentication &amp;lt;string&amp;gt; ();&lt;br /&gt;userAuth.Password   = "Secret";&lt;br /&gt;userAuth.UserID       = "User1";&lt;br /&gt;&lt;br /&gt;UserAuthentication &amp;lt;int&amp;gt; userAuth;&lt;br /&gt;        &lt;br /&gt;userAuth                  = new UserAuthentication &amp;lt;int&amp;gt; ();&lt;br /&gt;userAuth.Password    = 123456;&lt;br /&gt;userAuth.UserID        = "User2";&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;.NET framework supports different generic collections under the System.Collections.Generic namespace. These generic collections include:&lt;br /&gt;&lt;br /&gt;Stack &amp;lt;T&amp;gt; - a generic collection representing a Last-In-First-Out collection&lt;br /&gt;Queue &amp;lt;T&amp;gt; - a generic collection representing a First-In-First-Out collection&lt;br /&gt;List &amp;lt;T&amp;gt; - a generic collection of strongly type object list&lt;br /&gt;Dictionary &amp;lt;K, V&amp;gt; - a generic collection of key-pair values&lt;br /&gt;&lt;br /&gt;Let us see a generic List in action which accepts a strongly-typed parameter. We first define the strong-type Product followed by the generic list: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;public class Product&lt;br /&gt;{&lt;br /&gt;     string productName;&lt;br /&gt;&lt;br /&gt;     public Product (string pName)&lt;br /&gt;     {&lt;br /&gt;          productName = pName;&lt;br /&gt;     }&lt;br /&gt;&lt;br /&gt;     public string ProductDetails&lt;br /&gt;     {&lt;br /&gt;          get&lt;br /&gt;          {&lt;br /&gt;              return "Product-Name: " + productName;&lt;br /&gt;          }&lt;br /&gt;     }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public class ProductList &amp;lt;T&amp;gt; : IEnumerable &amp;lt;T&amp;gt; where T : Product&lt;br /&gt;{&lt;br /&gt;             List &amp;lt;T&amp;gt; productList = new List &amp;lt;T&amp;gt; ();&lt;br /&gt;&lt;br /&gt;     public void AddProduct (T product)&lt;br /&gt;     {&lt;br /&gt;          productList.Add (product);&lt;br /&gt;     }&lt;br /&gt;&lt;br /&gt;             public T GetProduct (int index)&lt;br /&gt;     {&lt;br /&gt;          return productList [index];&lt;br /&gt;     }&lt;br /&gt;           &lt;br /&gt;             IEnumerator &amp;lt;T&amp;gt; IEnumerable &amp;lt;T&amp;gt;.GetEnumerator ()&lt;br /&gt;     {&lt;br /&gt;          return productList.GetEnumerator ();&lt;br /&gt;     }&lt;br /&gt;&lt;br /&gt;              IEnumerator IEnumerable.GetEnumerator()&lt;br /&gt;     {&lt;br /&gt;          return productList.GetEnumerator ();&lt;br /&gt;     }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;We can now use the ProductList class to add and list products (a discussion of IEnumerable will follow shortly): &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;ProductList &amp;lt;Product&amp;gt; productList = new ProductList &amp;lt;Product&amp;gt; ();&lt;br /&gt;        &lt;br /&gt;productList.AddProduct (new Product ("Rice"));&lt;br /&gt;productList.AddProduct (new Product ("Milk"));&lt;br /&gt;productList.AddProduct (new Product ("Sugar"));&lt;br /&gt;&lt;br /&gt;… = ((Product) productList.GetProduct (1)).ProductDetails;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;Before I sum up the generics discussion, one last thing worth mentioning is constraints. If you have noticed in the ProductList class (and the Compare method), there is a use of ‘&lt;i&gt;where&lt;/i&gt;’ constraint. A constraint is a condition applied on the type parameter. We can use constraints to treat only specific types. For this reason the constraint ‘where T : Product’ is added to the class definition. This way we create a generic list which only deals with Product objects. We can have the following different constraints attached to the generic type:&lt;br /&gt;&lt;br /&gt;where T : class – type parameter is a reference type&lt;br /&gt;where T : struct – type parameter is a value type&lt;br /&gt;where T : new () – type parameter with a default constructor&lt;br /&gt;where T : interface – type parameter implements an interface&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Delegates&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;A delegate is an object which holds a reference to a method. When the delegate is called, the underlying method is invoked. This way a delegate behaves exactly like the referenced method. The method can either be static or an instance method. A delegate defines the method signature and any method with matching signature can be reference by the delegate. This makes it possible to change the reference to a different method programmatically and update the code in the methods without modifying the delegate. This simple concept of abstraction adds lots of power to the .NET Framework &lt;i&gt;(A detailed discussion of delegates is beyond the scope of this post. A detailed post or two would cover delegates, events, asynchronous callback and threading in the future)&lt;/i&gt;.&lt;br /&gt;&lt;br /&gt;Working with delegates is a pretty simple in C#. Always keep in mind the method signature when defining a delegate. Let us look at the syntax of defining a delegate:&lt;br /&gt;&lt;br /&gt;&lt;i&gt;delegate result-type Name (parameters);&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;The delegate keyword is used as prefix to define the delegate. The &lt;i&gt;result-type&lt;/i&gt; reflects the return type from the referenced method. The &lt;i&gt;Name&lt;/i&gt; is the identifier of the delegate and the optional comma separated &lt;i&gt;parameters&lt;/i&gt; are the input argument to the referenced method. The &lt;i&gt;result-type&lt;/i&gt; and &lt;i&gt;parameters&lt;/i&gt; define the signature of the delegate. Using the above syntax, we can create a delegate as following:&lt;br /&gt;&lt;br /&gt;public delegate void Calculate (int value, int amount);&lt;br /&gt;&lt;br /&gt;Any method with matching signature can be referenced by the above delegate. Let us define a method with the matching signature: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;public class Accounts&lt;br /&gt;{&lt;br /&gt;          public void DebitAccount (int x, int y)&lt;br /&gt;          {&lt;br /&gt;                    int sum;&lt;br /&gt;                    sum = ((x * 10) / y) * 2;&lt;br /&gt;                    // use sum…&lt;br /&gt;          }        &lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;We can now instantiate and invoke the delegate by referencing the DebitAccount method as following:&lt;br /&gt;&lt;br /&gt;Accounts objAccount = new Accounts ();&lt;br /&gt;Calculate calc  = new Calculate (objAccount.DebitAccount); // reference method&lt;br /&gt;calc (2, 3); // call delegate&lt;br /&gt;&lt;br /&gt;When we call the delegate, the DebitAccount method is invoked. &lt;br /&gt;&lt;br /&gt;Multicasting is one of the features provided by delegates. A multicast delegate can reference more than one method at a time. When the delegate is called, all the referenced methods are invoked. The methods are invoked in the order in which they are referenced by the delegate. Let us modify the Accounts class by adding the following method to it: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;public void CreditAccount (int x, int y)&lt;br /&gt;{&lt;br /&gt;           int average;&lt;br /&gt;           average = ((x / 2) + 10) - y;&lt;br /&gt;           // use average…&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;The calc delegate can now reference the above method using the compound assignment operator (+=):&lt;br /&gt;&lt;br /&gt;calc += objAccount.CreditAccount;&lt;br /&gt;&lt;br /&gt;Now if the call the delegate using calc (2, 3), both methods get invoked. Once you have used a delegate, the reference must be released. References can be removed using the compound subtraction statement or null value assignment as following: &lt;br /&gt;calc -= objAccount.CreditAccount; // remove reference to CreditAccount&lt;br /&gt;calc = null; // remove all references&lt;br /&gt;&lt;br /&gt;Delegates are also used for Asynchronous Callbacks. When asp.net receives a request for a page, it assigns a thread from the thread-pool to the requested page. In a synchronous call, the page holds on to the thread for the duration of the request, blocking calls to the thread for new requests. This is acceptable for a short lived request but if the request is time-bound such as calling multiple web services or an I/O bound job, the delay is annoying.&lt;br /&gt;&lt;br /&gt;Delegates help perform asynchronous tasks using &lt;i&gt;Method Callback&lt;/i&gt;. With this technique, the delegate invokes the time-consuming method in a separate thread and the control returns immediately. The time-bound task executes in the background while we can continue with our processing. When the background job is finished, control is transferred to a callback method which can handle the result and update any control. Let me demonstrate this concept with an example. We first write the time-consuming process as following: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;// the time consuming process&lt;br /&gt;public bool LongProcess (int wait)&lt;br /&gt;{&lt;br /&gt;          // your lengthy task goes here &lt;br /&gt;          System.Threading.Thread.Sleep (wait); // just for demonstration&lt;br /&gt;          return true; // return the result&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;Next we declare a delegate and use it to invoke the above method. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;// define the delegate&lt;br /&gt;public delegate bool LengthyProcessDelegate (int wait);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;User clicks on a button to start the process: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;// Use the delegate to start the lengthy process&lt;br /&gt;protected void StartProcessing_Click (object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;          LengthyProcessDelegate  lDelegate = new LengthyProcessDelegate (LongProcess);&lt;br /&gt;          lDelegate.BeginInvoke (5000, new AsyncCallback (LongProcessCallback), lDelegate);&lt;br /&gt;          for (int i = 0; i &amp;lt;= 50; i++)        &lt;br /&gt;          { &lt;br /&gt;                    // do something &lt;br /&gt;          }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;The above code first creates a new instance of the delegate which holds rerference to the time-consuming method. Next it calls the BeginInvoke method using the delegate. You must be wondering what this method is? Remember, when we declare a delegate, the compiler generates code similar to the following: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;class LengthyProcessDelegate : System.MulticastDelegate &lt;br /&gt;{ &lt;br /&gt;&lt;br /&gt;             // synchronous execution&lt;br /&gt;             public bool Invoke (int wait); &lt;br /&gt; &lt;br /&gt;            // asynchronous execution methods &lt;br /&gt;            public IAsyncResult BeginInvoke (int wait, &lt;br /&gt;                                               AsyncCallback callback, &lt;br /&gt;                                               object asyncState); &lt;br /&gt;&lt;br /&gt;            public bool EndInvoke (IAsyncResult result); &lt;br /&gt;} &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;The Invoke method is used for sychronous calls. The other two methods, BeginInvoke and EndInvoke handle the asynchronous activity.&lt;br /&gt;&lt;br /&gt;BeginInvoke method returns an instance of interface IAsyncResult. It accepts the same arguments as defined by the delegate plus two additional optional parameters. The first parameter is an instance of AsyncCallback (another delegate) which references the callback method. The second parameter is of type &lt;i&gt;object&lt;/i&gt; which can be used to pass any information. &lt;br /&gt;&lt;br /&gt;The EndInvoke method has the same return type as defined by the delegate. It accepts an instance of IAsyncResult. As mentioned above, BeginInvoke returns an instance of IAsyncResult. This instance is passed down to the callback method which is used by the EndInvoke method as parameter. It in turn returns the result of the time-consuming method which can be used for further processing. Let us look at the callback method in action: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;// Callback method&lt;br /&gt;public void LongProcessCallback (IAsyncResult result)&lt;br /&gt;{&lt;br /&gt;          LengthyProcessDelegate lDelegate= (LengthyProcessDelegate) result.AsyncState;&lt;br /&gt;          bool returnValue = lDelegate.EndInvoke (result);&lt;br /&gt;          // use returnvalue&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;As mentioned above, when BeginInvoke is called, the delegate invokes the callback method in a separate thread and the control returns to the program immediately. If you have noticed above, I have got a dummy loop after the call to BeginInvoke method. This is just to show you that the processing will continue and not wait for the time consuming process to complete.&lt;br /&gt;&lt;br /&gt;delegates also provide a rich programming model to handle Events. An event lets an object notify the program when its state changes. Events allow objects to provide noification to be responded. This simple concept is very important for inter-process communication where the change of state of one object signals other objects to respond. A good example of events is a Graphical User Interface. The program transfers the control to an event handler when an event such as Button-Click is triggered by the user action. Another example would be an Accounts object raising an event when a transaction is made. &lt;br /&gt;&lt;br /&gt;In C# events and delegates go hand-in-hand. Any object which triggers an event isn’t aware when the event is raised. This is left to a delegate which act as a bridge between the object and the event. Let us see this concept with a simple example. We begin with defining a delegate:&lt;br /&gt;&lt;br /&gt;// define the delegate&lt;br /&gt;public delegate void AccountDelegate (); // no input, output parameters&lt;br /&gt;&lt;br /&gt;Next we define an Accounts class. This class has a Transaction property which fires an event when its value changes. The event is defined using the AccountDelegate. Since the delegate’s signature does not have any input or output parameter, the event handler for the event will have a similar signature. The event handling method OnTransactionOccur is defined as virtual which can be overridden by derived classes. &lt;/span&gt; &lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;public class Accounts&lt;br /&gt;{&lt;br /&gt;         private int amount;&lt;br /&gt;         // define the event&lt;br /&gt;         public event AccountDelegate transactionComplete;&lt;br /&gt;&lt;br /&gt;         public int Transaction&lt;br /&gt;         {&lt;br /&gt;                    get { return amount; }&lt;br /&gt;&lt;br /&gt;                    set &lt;br /&gt;                    {&lt;br /&gt;                              if (value &amp;lt;= 100)&lt;br /&gt;                    amount--;&lt;br /&gt;                              else&lt;br /&gt;                                         amount++;&lt;br /&gt;&lt;br /&gt;                              OnTransactionOccur (); // raise the event&lt;br /&gt;                    }&lt;br /&gt;          }&lt;br /&gt;&lt;br /&gt;          protected virtual void OnTransactionOccur ()&lt;br /&gt;          {&lt;br /&gt;                  if (transactionComplete != null)&lt;br /&gt;                        transactionComplete ();&lt;br /&gt;          } &lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;We can now raise the event with the following code: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;public void StartProcessing_Click (object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;          Accounts account = new Accounts ();&lt;br /&gt;          // register the event&lt;br /&gt;          account.transactionComplete += new AccountDelegate (AccountEventHandler);&lt;br /&gt;&lt;br /&gt;          account.Transaction = 100; // raise the event&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;First we instantiate an object of Accounts class. Next we register the event using the delegate with the event handler AccountEventHandler. We then set the Transaction property to raise the event. Remember the base class method OnTransactionOccur is actually responsible for raising the event. As soon as the event is raised, the control is transferred to the following event handler. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;public static void AccountEventHandler ()&lt;br /&gt;{&lt;br /&gt;          // event handling code goes here&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Enumerators&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;Enumeration, a powerful .NET concept, allows us to iterator through a collection of objects. In .NET, enumerators are based on the Iterator Pattern. Using this pattern, we can access elements of an aggregate (combination of many elements) object without revealing the inner working. The terms Enumerators and Iterators are used interchangably but .NET uses the term &lt;i&gt;Enumerator&lt;/i&gt;.&lt;br /&gt;&lt;br /&gt;A class must implement the &lt;i&gt;IEnumerable&lt;/i&gt; interface to provide iteration. This interface exposes the following single method: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;public interface IEnumerable&lt;br /&gt;{&lt;br /&gt;          IEnumerator GetEnumerator ();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;The GetEnumerator method returns an object of IEnumerator interface. This object does the actual iteration on our collections. According to MSDN, Enumerators can be used to read the data in the collection, but they cannot be used to modify the underlying collection. Enumerator interface exposes the following methods: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;public interface IEnumerator&lt;br /&gt;{&lt;br /&gt;          bool MoveNext();&lt;br /&gt;          object Current{ get; }&lt;br /&gt;          void Reset();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;When we implement our own enumerators using the IEnumerator interface, the enumerator is positioned before the first element initially. To read the first (and subsequent) element, we use the MoveNext method. MoveNext method returns true until the end of the collection is reached. When MoveNext reaches the end of the collection, it returns false. To get the active element, we use the Current method. The Reset method positions the enumerator before the first element.&lt;br /&gt;&lt;br /&gt;Let me demonstrate the above concept by a simple example. I begin by defining (beaten to death :-) Product class as following: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;public class Product&lt;br /&gt;{&lt;br /&gt;          private string productID;&lt;br /&gt;          private string productName;&lt;br /&gt;&lt;br /&gt;          public Product (string id, string name)&lt;br /&gt;          {&lt;br /&gt;           productID   = id;&lt;br /&gt;                    productName = name;&lt;br /&gt;          }         &lt;br /&gt;&lt;br /&gt;          public override string ToString()&lt;br /&gt;          {&lt;br /&gt;                     return String.Format ("Product details are ID: {0}, Name: {1}", productID, &lt;br /&gt;                                                     productName);&lt;br /&gt;          }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;Next we define our Custom Collection class which implements IEnumerable interface: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;public class ProductCollection : IEnumerable&lt;br /&gt;{&lt;br /&gt;          private ArrayList productList;&lt;br /&gt;&lt;br /&gt;          public ProductCollection ()&lt;br /&gt;          {&lt;br /&gt;                   productList = new ArrayList ();&lt;br /&gt;&lt;br /&gt;                    productList.Add (new Product ("P1", "Tea"));&lt;br /&gt;                    productList.Add (new Product ("P2", "Beverage"));&lt;br /&gt;                    productList.Add (new Product ("P3", "Milk"));&lt;br /&gt;          }&lt;br /&gt;           &lt;br /&gt;          public IEnumerator GetEnumerator ()&lt;br /&gt;          {&lt;br /&gt;                      return ((IEnumerable) productList).GetEnumerator ();&lt;br /&gt;          }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;I have used an arraylist to define a product collection. Since the arraylist already implements the IEnumerable interface, we can get hold of the its enumerator object by calling its respective GetEnumerator method. The enumerator object can be used with foreach loop to provide enumeration: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;public void StartProcessing_Click (object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;          ProductCollection collection = new ProductCollection ();&lt;br /&gt;&lt;br /&gt;          foreach (Product p in collection)&lt;br /&gt;                 // ListBox1.Items. Add (p.ToString ()); - ading to a listbox&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;The foreach statements simplifies the enumeration code for us. Under the hood, when we use the &lt;i&gt;foreach&lt;/i&gt; loop, the compiler generates an initial call to GetEnumerator. It then uses MoveNext for each iteration to get the current item. Since the enumerator is positioned before the first element, the compiler doesn’t have to call the Reset method.&lt;br /&gt;&lt;br /&gt;We can also create our own Enumerator class by implementing the IEnumerator interface. Let us modify our ProductCollection class with a nested class as following: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;public class ProductEnumerator : IEnumerator&lt;br /&gt;{&lt;br /&gt;          private ProductCollection productCollection;&lt;br /&gt;          private int index;&lt;br /&gt;&lt;br /&gt;          public ProductEnumerator (ProductCollection collection)&lt;br /&gt;          {&lt;br /&gt;            productCollection = collection;&lt;br /&gt;                 index = -1;&lt;br /&gt;          }&lt;br /&gt;&lt;br /&gt;          public void Reset()&lt;br /&gt;          {&lt;br /&gt;            index = -1;&lt;br /&gt;          }&lt;br /&gt;&lt;br /&gt;          public object Current&lt;br /&gt;          {&lt;br /&gt;            get&lt;br /&gt;                 { return productCollection.productList[index]; }&lt;br /&gt;          }&lt;br /&gt;&lt;br /&gt;          public bool MoveNext()&lt;br /&gt;          {&lt;br /&gt;            index++;&lt;br /&gt;                 if (index &amp;gt;= productCollection.productList.Count)&lt;br /&gt;                               return false;&lt;br /&gt;                    else&lt;br /&gt;                               return true;&lt;br /&gt;           }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;Here is the tricky part. We used the GetEnumerator method of the ArrayList to get an enumerator object. We will modify that code to return an instance of our custom enumerator as following: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;public IEnumerator GetEnumerator()&lt;br /&gt;{&lt;br /&gt;             return (IEnumerator) new ProductEnumerator (this);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;One last thing worth mentioning are generic enumerators. These enumerators are used for a generic collection. The two interfaces are IEnumerable&amp;lt;T&amp;gt; and IEnumerator&amp;lt;T&amp;gt; found in System.Collections.Generic namespace. Both these interfaces inherit from their counterpart IEnumerable and IEnumerator. This means that generic enumerable objects are available both generically and non-generically. Let us first look at the IEnumerable&amp;lt;T&amp;gt; interface: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;public interface IEnumerable&amp;lt;T&amp;gt; : IEnumerable&lt;br /&gt;{&lt;br /&gt;             IEnumerator&amp;lt;T&amp;gt; GetEnumerator();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;IEnumerable&amp;lt;T&amp;gt; inherits from IEnumerable. This means any collection implementing IEnumerable&amp;lt;T&amp;gt; interface must define a generic and non-generic version of GetEnumerator method. So a generic collection class will have the following two implementations of GetEnumerator method: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;public IEnumerator&amp;lt;T&amp;gt; GetEnumerator()&lt;br /&gt;{&lt;br /&gt;          return new Enumerator&amp;lt;T&amp;gt;(this);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;IEnumerator IEnumerable.GetEnumerator()&lt;br /&gt;{&lt;br /&gt;          return new Enumerator&amp;lt;T&amp;gt;(this);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;The same concept applies to IEnumerator&amp;lt;T&amp;gt;. This interface is defined as following: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;public interface IEnumerator&amp;lt;T&amp;gt; : IDisposable, IEnumerator&lt;br /&gt;{&lt;br /&gt;           T Current { get; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;IEnumerator&amp;lt;T&amp;gt; interface implements IDisposable and IEnumerator interface. It has only one property. So any class implementing IEnumerator&amp;lt;T&amp;gt; inherits the rest of the members from IEnumerator and Idisposable interfaces. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Summary&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;In this post, we looked at some of the underlying concepts which help us better understand how LINQ works. Generics have introduced the concept of type parameter where the type definition is delayed till an object is instantiated. A place holder &amp;lt;T&amp;gt; defines a generic type. Generics apply to methods, classes and structures. We can apply constraints to our generic type to accept fixed type parameters. The .NET Framework ships with built in generic types such as Queue &amp;lt;T&amp;gt;, Stack &amp;lt;T&amp;gt; to reduce the development overhead.&lt;br /&gt;&lt;br /&gt;Another feature important to understand LINQ is delgates. Delegates are objects which hold reference to methods. A call to the delegate invokes the reference method. Delegate can also hold reference to multiple methods. This property is known as multicating. Delegates are also used for asynchronous callbacks. Using a delegate, a callback method is attached to a long running process. After the process has finished, the delegate transfers control to the callback method which can retrieve the result and process it. Delegates also move hand-in-hand with events which notify us of a change. We can then write our event handlers to responsd to these changes.&lt;br /&gt;&lt;br /&gt;We also looked at enumerators. Enumerators are used to iterate through the elements of an aggregate object. All enumerators implement IEnumerable and IEnumerator interfaces to provide iteration. The &lt;i&gt;foreach&lt;/i&gt; comes in handy to iterate through a collection. Generic collections can also take advantage of enumerators by implementing IEnumerable &amp;lt;T&amp;gt; and IENumerator &amp;lt;T&amp;gt; interfaces.&lt;br /&gt;&lt;br /&gt;When I sat down to write this post, I thought of explaining all the underlying concept in this post. But each topic is worth a separate post. For this reason, I will sum up the rest of the concept in the next post. Please do provide your feedback on this series and stay tuned for more…&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/834688215084300455-926350616212309409?l=dotnetpost.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetpost.blogspot.com/feeds/926350616212309409/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetpost.blogspot.com/2008/12/linq-explained-part-2.html#comment-form' title='10 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/926350616212309409'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/926350616212309409'/><link rel='alternate' type='text/html' href='http://dotnetpost.blogspot.com/2008/12/linq-explained-part-2.html' title='LINQ Explained– Part 2'/><author><name>Kashif Ahmad</name><uri>http://www.blogger.com/profile/02151423871584093787</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>10</thr:total></entry><entry><id>tag:blogger.com,1999:blog-834688215084300455.post-6579844294288510559</id><published>2008-10-21T23:21:00.000-07:00</published><updated>2009-03-05T11:43:46.099-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='General'/><title type='text'>Visual Studio Tips and Tricks</title><content type='html'>&lt;span style="font-family:verdana;"&gt;Stephen Walther has got some useful Visual Studio 2008 Tips and Tricks on his blog. You can find the post &lt;/span&gt;&lt;a href="http://weblogs.asp.net/stephenwalther/archive/2008/10/21/essential-visual-studio-tips-amp-tricks-that-every-developer-should-know.aspx"&gt;&lt;span style="font-family:verdana;"&gt;here&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:verdana;"&gt;.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/834688215084300455-6579844294288510559?l=dotnetpost.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetpost.blogspot.com/feeds/6579844294288510559/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetpost.blogspot.com/2008/10/visual-studio-tips-and-tricks.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/6579844294288510559'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/6579844294288510559'/><link rel='alternate' type='text/html' href='http://dotnetpost.blogspot.com/2008/10/visual-studio-tips-and-tricks.html' title='Visual Studio Tips and Tricks'/><author><name>Kashif Ahmad</name><uri>http://www.blogger.com/profile/02151423871584093787</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-834688215084300455.post-5712155594612663996</id><published>2008-10-21T23:06:00.000-07:00</published><updated>2009-01-06T22:48:01.390-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='LINQ'/><title type='text'>LINQ Explained– Part 1</title><content type='html'>&lt;span style="font-family:Verdana;"&gt;This is first installment of a multi-part tutorial series on Language Integrated Query or LINQ. In this series, my goal is to provide the readers with a detailed overview of LINQ. LINQ comes as a built-in feature with Visual Studio 2008 however; LINQ can also be used with Visual Studio 2005 by downloading the May 2006 CTP &lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=1e902c21-340c-4d13-9f04-70eb5e3dceea&amp;displaylang=en"&gt;here&lt;/a&gt;. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;What is LINQ&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;LINQ is a programming model which enables us to query and modify data independent of a data source. It is a set of extensions that adds native support for queries to the .NET Framework. With LINQ support, ‘Queries’ have become a first-class citizen within any .NET languages such as C# and VB.NET. By providing data abstraction over different data domains, LINQ provides a unified approach to manage data. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Why use LINQ&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;Today (and always :-) developers are responsible for managing data in their applications. The data belongs to different data domains and each domain comes with its unique set of rules to play with e.g. SQL is used for relational databases, XQuery/DOM are used to handle XML Documents and different Application Programming Interfaces (APIs) are used to manage Text files, Objects, Graphs, Registry, Active Directory etc. The developers are faced with the dilemma to master different data domains for the same purpose - to handle data. Wouldn’t it be nice to have a single set of rules to manage all our data requirements? This is where LINQ comes in handy. LINQ provides a unified programming model to manage data from different data sources. Hence with LINQ, we can invest our efforts in handling the business logic and not worrying about the syntax to manage data. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;LINQ syntax and working&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;With LINQ, the notion of queries is now a built-in concept in the .NET Framework. The LINQ syntax (known as Query Expression) is a reminiscent of SQL. But this syntax is not limited to relational databases rather applies across all data domains under its umbrella. Following is a simple example of a LINQ Query which operates on a string array: &lt;/span&gt; &lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="CSharp"&gt;&lt;br /&gt;string [] fruits = { "apple", "banana", "orange", "pineapple", "carrot" };&lt;br /&gt;&lt;br /&gt;var query =&lt;br /&gt;             from fruit in fruits&lt;br /&gt;             where (fruit == "orange" || fruit == "pineapple")&lt;br /&gt;             select fruit; &lt;br /&gt;&lt;br /&gt;foreach (var fruit in query)&lt;br /&gt;{&lt;br /&gt;             ListBox1.Items.Add (fruit);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;We will have a detailed look at LINQ syntax in the following posts. For now let us see what the above code does. We have an array of strings and a SQL-type query operates on this array. The query returns a subset of the array to an object of type var. The foreach-loop iterates through the object and displays the result. Simple isn’t it?&lt;br /&gt;&lt;br /&gt;The worth noting point is that the same syntax above applies to a Relational database, DataSets, XML files or any other data domain. Our interface to handle the data remains the same but at the other end; the data domain can change depending on our requirements. This ability to have the same set of rules to access data across different domains is notable. I am sure, by now, you have started to see the strength of LINQ. The LINQ architecture depends on many .NET Framework features such as Generics, Delegates, Anonymous &amp; Extension Methods etc. My next post will provide a detailed overview of these features.&lt;br /&gt;&lt;br /&gt;LINQ comes in many flavors (LINQ Providers) to manage different data domains. Don’t confuse LINQ syntax with flavors. The syntax remains the same (with slight variation) across different providers. But the features may vary from one provider to the other e.g. the same LINQ syntax will fetch an Element/Node from an XML document but a DataRow from a database. Each LINQ Provider is responsible for converting the LINQ Expression to a form compatible with the underlying data source. LINQ has the following different flavors:&lt;br /&gt;&lt;br /&gt;LINQ to Objects: Used to query in-memory collection of objects&lt;br /&gt;LINQ to SQL: Handles data from SQL Server &amp; SQL Server Compact databases&lt;br /&gt;LINQ to Entities: Operates on object entities&lt;br /&gt;LINQ to DataSet: Query data from DataSets&lt;br /&gt;LINQ to XML: Handles data from XML Documents&lt;br /&gt;Third Party: In the future we will see more providers written by third parties for different data sources. &lt;br /&gt;The detailed discussion of these providers will be the topic of a future posts. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: 14px; font-family: Verdana; color: Maroon; font-weight: bold;"&gt;Summary&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Verdana;"&gt;This installment provided an overview of Language Integrated Query. LINQ is a powerful technology which provides a unified programming model to manage data from different data sources. Queries now have native support in .NET Framework. LINQ syntax (Query Expression) resembles SQL syntax. There are several LINQ Providers for different data sources. Following are some useful links to know more about LINQ:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/netframework/aa904594.aspx"&gt;The LINQ Project&lt;/a&gt;&lt;br /&gt;&lt;a href="http://weblogs.asp.net/scottgu/archive/2006/05/14/Using-LINQ-with-ASP.NET-_2800_Part-1_2900_.aspx"&gt;ScottGu on LINQ&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;In the next article, we will look at some of the C# Language features that are needed to understand to work with LINQ efficiently. So stay tuned… &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/834688215084300455-5712155594612663996?l=dotnetpost.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetpost.blogspot.com/feeds/5712155594612663996/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetpost.blogspot.com/2008/10/linq-explained-part-1.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/5712155594612663996'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/5712155594612663996'/><link rel='alternate' type='text/html' href='http://dotnetpost.blogspot.com/2008/10/linq-explained-part-1.html' title='LINQ Explained– Part 1'/><author><name>Kashif Ahmad</name><uri>http://www.blogger.com/profile/02151423871584093787</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-834688215084300455.post-3356626538078593885</id><published>2008-10-13T21:13:00.000-07:00</published><updated>2009-03-05T11:43:46.100-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='General'/><title type='text'>.NET Framework Survey</title><content type='html'>&lt;span style="font-family:verdana;"&gt;Scott Hanselman is hosting a survey about the .NET Framework. You can participate in this survey at the following address:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;a href="http://www.hanselman.com/blog/SurveyTimeWhatNETFrameworkFeaturesDoYouUse.aspx"&gt;&lt;span style="font-family:verdana;"&gt;http://www.hanselman.com/blog/SurveyTimeWhatNETFrameworkFeaturesDoYouUse.aspx&lt;/span&gt;&lt;/a&gt;&lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/834688215084300455-3356626538078593885?l=dotnetpost.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetpost.blogspot.com/feeds/3356626538078593885/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetpost.blogspot.com/2008/10/net-framework-survey.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/3356626538078593885'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/3356626538078593885'/><link rel='alternate' type='text/html' href='http://dotnetpost.blogspot.com/2008/10/net-framework-survey.html' title='.NET Framework Survey'/><author><name>Kashif Ahmad</name><uri>http://www.blogger.com/profile/02151423871584093787</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-834688215084300455.post-6413701157167759278</id><published>2008-10-13T02:10:00.000-07:00</published><updated>2008-10-26T23:08:55.979-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='General'/><title type='text'>New .NET &amp; Architecture blog</title><content type='html'>&lt;span style="font-family:verdana;"&gt;I am setting up this blog to share my thoughts, ideas and experiences working as a .NET developer. This blog is not the first of its kind rather a mere addition to what so many geeks are doing around. The .net framework is a power object-oriented technology for rapid application development. Also Microsoft is now geared up focusing on architecture for software development. This combination of sound architecture and the .net framework has brought a world of goodness to the developer community.&lt;br /&gt;&lt;br /&gt;I am a web developer working exclusively with the .net framework (and plan to continue working :-). My areas of interest include Web Services, WCF, AJAX and Design Pattern. I hope this blog will help us share information and learn from each other’s knowledge. So stay tuned and see you soon :-.&lt;/span&gt;&lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/834688215084300455-6413701157167759278?l=dotnetpost.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/6413701157167759278'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/834688215084300455/posts/default/6413701157167759278'/><link rel='alternate' type='text/html' href='http://dotnetpost.blogspot.com/2008/10/my-new-aspnet-architecture-blog.html' title='New .NET &amp; Architecture blog'/><author><name>Kashif Ahmad</name><uri>http://www.blogger.com/profile/02151423871584093787</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author></entry></feed>
