<?xml-stylesheet type="text/xsl" href="/rss.xsl" media="screen"?><rss version="2.0"><channel><title>softlogger Latest Articles ::DatabaseSQL</title><link>http://softlogger.com</link><description>softlogger Latest Articles ::DatabaseSQL</description><ttl>180</ttl><item><title>A future world without the SQL Server Image/Text/NText data types. Now's the time to start planning for that future...</title><link>http://softlogger.com/20584/DatabaseSQL/a-future-world-without-the-sql-server-image-text-ntext-data-types-now-s-the-time-to-start-planning-for-that-future-.aspx</link><description>&lt;a href="http://blogs.technet.com/josebda/default.aspx"&gt;Jose Barreto's Blog&lt;/a&gt; - &lt;a href="http://blogs.technet.com/josebda/archive/2008/03/17/sql-server-2008-and-unstructured-data.aspx"&gt;SQL Server 2008 and Unstructured Data&lt;/a&gt;  &lt;blockquote&gt;   &lt;p&gt;&amp;quot;SQL Server 2008 introduces two new options to store unstructured data, in addition to the current BLOB support we have in SQL Server 2005. &lt;/p&gt;    &lt;p&gt;&lt;strong&gt;IMAGE&lt;/strong&gt;&lt;/p&gt;    &lt;p&gt;Back in SQL Server 2000 and SQL Server 7 days, we used the IMAGE data type to store binary large objects (a.k.a. BLOBs). Large, by the way, is defined as anything that would not fit a SQL Server data page (around 8,000 bytes). This data type is still present in SQL Server 2005 today, &lt;strong&gt;but it should be going away soon.&lt;/strong&gt; &lt;strong&gt;The current recommendation is to &amp;#8220;avoid using these data types in new development work, and plan to modify applications that currently use them.&amp;#8221;&lt;/strong&gt;&amp;#160; &lt;strong&gt;This applies also to the similar TEXT and NTEXT data types.&lt;/strong&gt; [GD: Emphasis added]&lt;/p&gt;    &lt;p&gt;This is described in more detail at &lt;a href="http://msdn2.microsoft.com/en-us/library/ms187993.aspx"&gt;http://msdn2.microsoft.com/en-us/library/ms187993.aspx&lt;/a&gt;. &lt;/p&gt;    &lt;p&gt;&lt;strong&gt;VARBINARY&lt;/strong&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;blockquote&gt;   &lt;p&gt;To replace those, SQL Server 2005 introduced the concept of using the VARBINARY(MAX) data type....&lt;/p&gt; &lt;/blockquote&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;strong&gt;FILESTREAM&lt;/strong&gt;&lt;/p&gt;    &lt;p&gt;A new option in SQL Server 2008 is to use a FILESTREAM attribute in a VARBINARY column. This allows you to store the actual data on the server&amp;#8217;s file system...&lt;/p&gt;    &lt;p&gt;&lt;strong&gt;RBS&lt;/strong&gt;&lt;/p&gt;    &lt;p&gt;SQL Server 2008 also introduces a new client-side API that allows for storing BLOBs on a Remote BLOB store (RBS). &lt;/p&gt;    &lt;p&gt;...&amp;quot;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;&lt;a href="Important:  "&gt;SQL Server 2005 Books Online (September 2007)&lt;/a&gt; - &lt;a href="http://msdn2.microsoft.com/en-us/library/ms187993.aspx"&gt;ntext, text, and image (Transact-SQL)&lt;/a&gt;&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&amp;quot;&lt;strong&gt;Important&lt;/strong&gt;: &lt;/p&gt;    &lt;p&gt;&lt;b&gt;ntext&lt;/b&gt;, &lt;b&gt;text&lt;/b&gt;, and &lt;b&gt;image&lt;/b&gt; data types will be removed in a future version of Microsoft SQL Server. Avoid using these data types in new development work, and plan to modify applications that currently use them. Use &lt;a href="http://msdn2.microsoft.com/en-us/library/ms186939.aspx"&gt;nvarchar(max)&lt;/a&gt;, &lt;a href="http://msdn2.microsoft.com/en-us/library/ms176089.aspx"&gt;varchar(max)&lt;/a&gt;, and &lt;a href="http://msdn2.microsoft.com/en-us/library/ms188362.aspx"&gt;varbinary(max)&lt;/a&gt; instead. For more information, see &lt;a href="http://msdn2.microsoft.com/en-us/library/ms178158.aspx"&gt;Using Large-Value Data Types&lt;/a&gt;.&lt;/p&gt;    &lt;p&gt;...&amp;quot;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;We've been warned. SQL Server 2011 without the Image/Text/NText data types? Could be...&lt;/p&gt;  &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/coolthingoftheday?a=jKQ8yUF"&gt;&lt;img src="http://feeds.feedburner.com/~f/coolthingoftheday?i=jKQ8yUF" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/coolthingoftheday?a=xQUiLPF"&gt;&lt;img src="http://feeds.feedburner.com/~f/coolthingoftheday?i=xQUiLPF" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/coolthingoftheday?a=NbCXwyF"&gt;&lt;img src="http://feeds.feedburner.com/~f/coolthingoftheday?i=NbCXwyF" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/coolthingoftheday/~4/253681586" height="1" width="1"/&gt;&lt;img alt="via softlogger.com" src="http://softlogger.com/postview.aspx?ArticleID=20584"&gt;</description><author>Gregs Cool [Insert Clever Name] of the Day</author><pubDate>2008-03-23T00:00:00</pubDate><category>Database,SQL</category></item><item><title>Introducing SQL Server Data Services ( SSDS ) by Nigel Ellis - Mix08 Video Download of Presentation</title><link>http://softlogger.com/20366/DatabaseSQL/introducing-sql-server-data-services--ssds--by-nigel-ellis--mix08-video-download-of-presentation.aspx</link><description>The speakers for the Microsoft Sync Framework, ADO.NET Data Services, and SQL Server Data Services mentioned the one-two punch you get from leveraging these services together. SQL Server Data Services is a web facing data storage and processing utility to be launched by Microsoft during the first-half of 2009...&lt;img src ="http://davidhayden.com/blog/dave/aggbug/3492.aspx" width = "1" height = "1" /&gt;&lt;img alt="via softlogger.com" src="http://softlogger.com/postview.aspx?ArticleID=20366"&gt;</description><author>David Hayden - Florida .NET Developer - C# and SQL Server</author><pubDate>2008-03-12T00:00:00</pubDate><category>Database,SQL</category></item><item><title>Let Live Search know when you update your website</title><link>http://softlogger.com/20268/DatabaseSQL/let-live-search-know-when-you-update-your-website.aspx</link><description>&lt;p&gt;
&lt;strong&gt;UPDATE&lt;/strong&gt;: &lt;em&gt;Google also has a ping service that works in the exact same way. You can find it at http://www.google.com/ping?sitemap=[your sitemap URL]&lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
Microsoft&amp;rsquo;s Live Search along with Yahoo and Ask decided some time ago to support Google&amp;rsquo;s &lt;a href="http://www.sitemaps.org/protocol.php"&gt;XML sitemap format&lt;/a&gt;. So if you already have added support for a Google sitemap on your website, it now also works on the other major search engines. 
&lt;/p&gt;
&lt;p&gt;
The &lt;a href="http://blogs.msdn.com/webmaster/archive/2008/02/27/microsoft-to-support-cross-domain-sitemaps.aspx"&gt;new thing&lt;/a&gt; is that Live Search have added a ping service that let&amp;rsquo;s you notify it&amp;nbsp;when your sitemap has been updated. Then Live Search will index the changes and make them appear faster in the search results (or at least so I think, otherwise it wouldn&amp;rsquo;t make much sense to have a ping service). 
&lt;/p&gt;
&lt;p&gt;
It&amp;rsquo;s very simple to ping Live Search. Simply make a request to &lt;em&gt;http://webmaster.live.com/ping.aspx?siteMap=[your sitemap URL]&lt;/em&gt; in any way that suits you best. Do it in a browser manually or let your CMS or blogging engine do it for you. 
&lt;/p&gt;
&lt;h2&gt;For BlogEngine.NET users&lt;/h2&gt;
&lt;p&gt;
If you use BlogEngine.NET then you already have a compatible sitemap. It&amp;rsquo;s located at &lt;em&gt;example.com/sitemap.axd&lt;/em&gt;. See &lt;a href="http://blog.madskristensen.dk/sitemap.axd" title="My XML sitemap"&gt;my sitemap here&lt;/a&gt;. I&amp;rsquo;ve written an extension that sends the ping automatically whenever a post or page is created or edited and when a comment is added. 
&lt;/p&gt;
&lt;p&gt;
Download the extension below, unzip it and place the &lt;em&gt;LiveSearchPinger.cs&lt;/em&gt; file in the &lt;em&gt;App_Code/Extensions&lt;/em&gt; folder of your BlogEngine.NET website. 
&lt;/p&gt;
&lt;p&gt;
&lt;a rel="enclosure" href="http://blog.madskristensen.dk/file.axd?file=LiveSearchPinger.zip"&gt;LiveSearchPinger.zip (727 bytes)&lt;/a&gt; 
&lt;/p&gt;
&lt;img alt="via softlogger.com" src="http://softlogger.com/postview.aspx?ArticleID=20268"&gt;</description><author>.NET slave</author><pubDate>2008-03-12T00:00:00</pubDate><category>Database,SQL</category></item><item><title>Decompiling Silverlight 2 Apps – Enter the XAP</title><link>http://softlogger.com/20225/DatabaseSQL/decompiling-silverlight-2-apps--enter-the-xap.aspx</link><description>When you build a Silverlight 2 application, you compile your source files (inc. XAML and embedded resources) into assemblies (dlls). Those assemblies (plus any 3rd party ones plus MS assemblies that are not part of Silverlight) are then collected together along with a manifest into a packaged archive – or in other words, a ZIP file. Except, the extension is changed to be a .XAP (pronounced "ZAP"). The benefits of packaging everything into a XAP should be obvious but in case they are not, &lt;a href="http://community.irritatedvowel.com/blogs/pete_browns_blog/archive/2008/03/05/Xap_2100_-App_2100_-Pow_2100_-Packaging-and-Application-Startup-in-Silverlight-2-Beta-1-_2D00_-Part-1.aspx"&gt;Pete has discussed that on his blog (inc. screenshots)&lt;/a&gt;. Note that if your web server is on IIS (prior to version 7) you need to &lt;a href="http://simplesilverlight.wordpress.com/2008/03/07/register-xap-file-in-iis/"&gt;register that MIME type&lt;/a&gt;. &lt;em&gt;As an aside, my web server happens to be Apache (shocking I know!) and I had to configure nothing – it just worked.&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;So, if I had given you a Winforms EXE file you wouldn't ask me for the source code, you would probably just pass it through your favourite decompiler and you've got it all. Same with Silverlight apps: if I point you to my web page that is running a Silverlight app (e.g. &lt;a href="http://www.danielmoth.com/Blog/2008/03/silverlight-browser-integration-aka.html"&gt;the one from this post&lt;/a&gt;) all you have to do is:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;1. View HTML source&lt;/strong&gt;, e.g. for this: http://www.danielmoth.com/SL/HtmlBridge/index.html&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;2. Locate the tag that points to a XAP file&lt;/strong&gt; and copy the full path, e.g. ClientBin/DemoIntegration.xap&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;3. Use that path to "Save As"&lt;/strong&gt; the xap file locally.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;4. Rename the XAP file to ZIP&lt;/strong&gt; and explode it to get the DLLs inside.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;5. Party away by tossing the DLL(s) to the decompiler&lt;/strong&gt;, e.g. Reflector.&lt;br /&gt;&lt;br /&gt;Obviously authors of serious SL apps may not condone that behaviour, but feel free to do it with all of mine, for example the &lt;a href="http://www.danielmoth.com/Blog/2008/03/multiscaleimage-with-mouse-support-ish.html"&gt;DeepZoom/MultiScaleImage that I have now updated to also use mouse wheel&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;br/&gt;&lt;hr/&gt;
&lt;span style="font-style: italic;font-size:85%;"&gt;Comments about this post welcome at &lt;a href="http://www.danielmoth.com/Blog/"&gt;the original blog&lt;/a&gt;&lt;/span&gt;.&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/DanielMoth?a=PLXFtrF"&gt;&lt;img src="http://feeds.feedburner.com/~f/DanielMoth?i=PLXFtrF" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/DanielMoth?a=Re1gIoF"&gt;&lt;img src="http://feeds.feedburner.com/~f/DanielMoth?i=Re1gIoF" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/DanielMoth?a=fqqLZbf"&gt;&lt;img src="http://feeds.feedburner.com/~f/DanielMoth?i=fqqLZbf" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/DanielMoth?a=9AlGZzf"&gt;&lt;img src="http://feeds.feedburner.com/~f/DanielMoth?i=9AlGZzf" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/DanielMoth?a=AanA5HF"&gt;&lt;img src="http://feeds.feedburner.com/~f/DanielMoth?i=AanA5HF" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/DanielMoth?a=k5at4rf"&gt;&lt;img src="http://feeds.feedburner.com/~f/DanielMoth?i=k5at4rf" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/DanielMoth?a=ZohuOAF"&gt;&lt;img src="http://feeds.feedburner.com/~f/DanielMoth?i=ZohuOAF" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/DanielMoth/~4/248456118" height="1" width="1"/&gt;&lt;img alt="via softlogger.com" src="http://softlogger.com/postview.aspx?ArticleID=20225"&gt;</description><author>The Moth</author><pubDate>2008-03-09T00:00:00</pubDate><category>Database,SQL</category></item><item><title>Building Great AJAX Applications from Scratch Using ASP.NET 3.5 and Visual Studio 2008 - MIX 08 Presentation</title><link>http://softlogger.com/20375/DatabaseSQL/building-great-ajax-applications-from-scratch-using-asp-net-3-5-and-visual-studio-2008--mix-08-presentation.aspx</link><description>&lt;H1&gt;&lt;FONT face=Verdana&gt;Building Great AJAX Applications from Scratch Using ASP.NET 3.5 and Visual Studio 2008 - MIX 08 Presentation&lt;/FONT&gt;&lt;/H1&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;by &lt;A href="http://www.davidhayden.com/"&gt;David Hayden&lt;/A&gt;, &lt;A href="http://www.davidhayden.com/"&gt;Florida ASP.NET Web Developer&lt;/A&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;IMG alt="Building Great AJAX Applications" src="http://www.davidhayden.com/photos/MIX08BuildingGreatAJAXApplications.jpg" align=right&gt;Brad Abrams hit a homerun with his MIX 08 Presentation on &lt;STRONG&gt;Building Great AJAX Applications from Scratch Using ASP.NET 3.5 and Visual Studio 2008&lt;/STRONG&gt;.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;I watched the video and was really, really impressed with his coverage of:&lt;/FONT&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;Visual Studio 2008 CSS and Style Sheet Management&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;LINQ To SQL Basics&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;Introduction to the new ListView and DataPager Controls in .NET 3.5 Framework&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;Using the ASP.NET AJAX Server-Side UpdatePanel and UpdateProgress Controls&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;Client-Side AJAX Calls using JavaScript to WCF Services&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;Use of the AJAX Control Toolkit for a Richer User Exprerience&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;Switching Between Internet Explorer and Firefox /&amp;nbsp;FireBug&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;Demonstrating&amp;nbsp;a ScriptCombining Feature that will be released in a .NET 3.5 SP1 it seems&lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;A nice and realistic list of AJAX Website Features demonstrated on-the-fly that one would want to use in a real-world application.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;He even &lt;/FONT&gt;&lt;A href="http://blogs.msdn.com/brada/archive/2008/03/06/mix08-session-overview-building-great-ajax-applications-from-scratch-using-asp-net-3-5-and-visual-studio-2008.aspx" target=_blank&gt;&lt;FONT face=Verdana size=2&gt;posted a great summary&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; of his talk as well as provided the sample code for download on his blog. Still, I would watch the video because he does a great job of walking you through building the ASP.NET AJAX Web Application piece-by-piece.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;H2&gt;&lt;FONT face=Verdana&gt;MIX 08 Sessions Viewed&lt;/FONT&gt;&lt;/H2&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2008/03/06/ASPNETDynamicDataWebsitesPresentationMix08.aspx"&gt;Developing Data-Driven Web Applications Using ASP.NET Dynamic Data&lt;/A&gt;&lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;H2&gt;&lt;FONT face=Verdana&gt;ASP.NET AJAX Tutorials&lt;/FONT&gt;&lt;/H2&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2008/03/03/AJAXControlToolkitVisualStudio2008NET35FrameworkReleased.aspx"&gt;&lt;FONT face=Verdana color=#0000ff size=2&gt;AJAX Control Toolkit for Visual Studio 2008 and .NET 3.5 Released - 3.0.20229&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; &lt;/FONT&gt;
&lt;LI&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2008/02/21/DropthingsAjaxWebPortal.aspx"&gt;&lt;FONT face=Verdana color=#0000ff size=2&gt;Dropthings - Ajax Web Portal - Sample Application of AJAX, LINQ To SQL, LINQ To XML, Windows Workflow&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; &lt;/FONT&gt;
&lt;LI&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2008/02/06/ASPNETMVCFrameworkAJAXjQueryJavaScriptSerializerLINQ.aspx"&gt;&lt;FONT face=Verdana color=#0000ff size=2&gt;ASP.NET MVC Framework and AJAX Using jQuery, JavaScriptSerializer and LINQ&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; &lt;/FONT&gt;
&lt;LI&gt;&lt;A href="http://www.pnpguidance.net/Screencast/DayOfPatternsPracticesScreencastWCSFAJAXDynamicDataMVCFramework.aspx"&gt;&lt;FONT face=Verdana color=#0000ff size=2&gt;Day Of Patterns &amp;amp; Practices Screencast - WCSF AJAX DynamicData ASP.NET MVC Framework&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; &lt;/FONT&gt;
&lt;LI&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2007/11/30/ASPNETAJAXPageRequestManagerbeginRequestendRequestEventsUpdateProgress.aspx"&gt;&lt;FONT face=Verdana color=#0000ff size=2&gt;ASP.NET AJAX PageRequestManager beginRequest and endRequest Events for UpdateProgress&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; &lt;/FONT&gt;
&lt;LI&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2007/11/29/ASPNETAJAXProgressIndicatorRealTimeSearchFunctionalityYUIStyle.aspx"&gt;&lt;FONT face=Verdana color=#0000ff size=2&gt;ASP.NET AJAX Progress Indicator with Real-Time Search Functionality - YUI Style&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; &lt;/FONT&gt;
&lt;LI&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2007/11/20/FreeASPNETAJAXELearningClinic.aspx"&gt;&lt;FONT face=Verdana color=#0000ff size=2&gt;Free ASP.NET AJAX E-Learning Clinic&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; &lt;/FONT&gt;
&lt;LI&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2007/11/16/EnableAJAXExistingASPNETWebsiteUsingWCSF.aspx"&gt;&lt;FONT face=Verdana color=#0000ff size=2&gt;Enable AJAX on Existing ASP.NET Website Using WCSF&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; &lt;/FONT&gt;
&lt;LI&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2007/11/13/VS2008JavascriptDebugging.aspx"&gt;&lt;FONT face=Verdana color=#0000ff size=2&gt;VS2008 Javascript Debugging&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; &lt;/FONT&gt;
&lt;LI&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2007/11/12/SearchingASPNETAJAXWebServicesUpdatePanel.aspx"&gt;&lt;FONT face=Verdana color=#0000ff size=2&gt;Searching via ASP.NET AJAX and Web Services without UpdatePanel&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; &lt;/FONT&gt;
&lt;LI&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2007/11/10/SearchBundleWCSFRealTimeSearchFunctionalityASPNETAJAX.aspx"&gt;&lt;FONT face=Verdana color=#0000ff size=2&gt;Search Bundle in WCSF - Real-Time Search Functionality using ASP.NET AJAX&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; &lt;/FONT&gt;
&lt;LI&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2007/11/10/ConsumingWebServiceUsingASPNETAJAXPartII.aspx"&gt;&lt;FONT face=Verdana color=#0000ff size=2&gt;Consuming Web Service using ASP.NET AJAX Part II&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; &lt;/FONT&gt;
&lt;LI&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2007/11/07/CallingWebServicesUsingClientSideASPNETAJAXServerSideValidation.aspx"&gt;&lt;FONT face=Verdana color=#0000ff size=2&gt;Calling Web Services using Client-Side ASP.NET AJAX for Server-Side Validation&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; &lt;/FONT&gt;
&lt;LI&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2007/11/05/ASPNETAJAXServerSideValidationServerSideValidationExtenderValidationGuidanceBundle.aspx"&gt;&lt;FONT face=Verdana color=#0000ff size=2&gt;ASP.NET AJAX Server-Side Validation - ServerSideValidationExtender in Validation Guidance Bundle&lt;/FONT&gt;&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;News Feed: &lt;/FONT&gt;&lt;A href="http://www.davidhayden.com/"&gt;&lt;FONT face=Verdana size=2&gt;http://www.davidhayden.com/&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;&lt;img src ="http://davidhayden.com/blog/dave/aggbug/3484.aspx" width = "1" height = "1" /&gt;&lt;img alt="via softlogger.com" src="http://softlogger.com/postview.aspx?ArticleID=20375"&gt;</description><author>David Hayden - Florida .NET Developer - C# and SQL Server</author><pubDate>2008-03-07T00:00:00</pubDate><category>Database,SQL</category></item><item><title>SQL Server 2008 FILESTREAM - Writing a file to a FILESTREAM column</title><link>http://softlogger.com/19953/DatabaseSQL/sql-server-2008-filestream--writing-a-file-to-a-filestream-column.aspx</link><description>&lt;p&gt;&lt;a href="http://blogs.msdn.com/zowens/default.aspx"&gt;Zach Skyles Owens&lt;/a&gt; - &lt;a href="http://blogs.msdn.com/zowens/archive/2008/03/03/sql-server-2008-filestream-and-wpf-mediaelement-part-2-writing-filestream-data.aspx"&gt;SQL Server 2008 FILESTREAM and WPF MediaElement - Part 2 (Writing FILESTREAM Data)&lt;/a&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Wow...  It's been a long time coming.  I promised that I would explain in more detail how to write FILESTREAM data to SQL Server 2008.  This is the &lt;a href="http://blogs.msdn.com/zowens/archive/2007/10/11/sql-server-2008-filestream-and-wpf-mediaelement.aspx"&gt;second article in a series&lt;/a&gt; and uses the sample published on the &lt;a href="http://codeplex.com/SQLSrvE2E"&gt;SQL Server Community Samples site on CodePlex&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Writing data to a varbinary(max) FILESTREAM column in SQL is a bit more involved then just opening a file on the filesystem.  SQL Server needs to manage this operation within a transaction which adds a bit of complexity.  Here are the basic steps...  These steps apply both to reading and writing.&lt;/p&gt;&lt;p&gt;Start a SQL Server transaction &lt;/p&gt;&lt;ol&gt;&lt;li&gt;Insert a row into the table containing metadata &lt;/li&gt;&lt;li&gt;Select the PathName from SQL Server which will be used to get a handle &lt;/li&gt;&lt;li&gt;Open a handle for writing using sqlncli10.dll &lt;/li&gt;&lt;li&gt;Use that handle within System.IO classes &lt;/li&gt;&lt;li&gt;Commit the transaction&lt;/li&gt;&lt;li&gt;Now that the basic steps are laid out, let's take a closer look&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;...&lt;/p&gt;&lt;p&gt;So...  Here's where I think things get interesting.  You can see that the SELECT statement above calls the PathName() method of the FILESTREAM column.  Here's an example of the results from the query above. &lt;em&gt;Note the use of UDTs and CLR!&lt;/em&gt;&lt;/p&gt;&lt;p&gt;\\ZOWENS-NB3\MSSQLSERVER\v1\FilestreamWpfHttp\dbo\media\file\4C3C9C2D-8268-43FF-8317-D507319FE21C&lt;/p&gt;&lt;p&gt;This is a "virtual" path managed by SQL Server.  It consists of \\COMPUTER_NAME, followed by a configurable handler \MSSQLSERVER...&lt;/p&gt;&lt;p&gt;...&lt;/p&gt;&lt;p&gt;The code above uses a simple C# class "SqlNativeClient" that wraps the sqlncli10.dll I mentioned above.  This C# class is key to working with FILESTREAM in managed code.  You can see that we passed in the sqlFilePath variable from the PathName() query.&lt;/p&gt;&lt;pre&gt;// Open up a new stream to write the file to the blob.&lt;br /&gt;System.IO.FileStream destBlob = new System.IO.FileStream(handle, FileAccess.Write);&lt;/pre&gt;&lt;p&gt;"Old school" System.IO file manipulation using the handle obtained from the SqlNativeClient class above.&lt;/p&gt;&lt;pre&gt;// Commit transaction       &lt;br /&gt;txn.Commit();&lt;/pre&gt;&lt;p&gt;There you have it...  It's not rocket science but there are a few tricks."&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;This article shows the magic behind the new FILESTREAM column attribute. It shows how it's not just some kind of uber-BLOB, but the delegating of responsibility based on capability. Showing how the SQL does what it is good at, while delegating to the file system to do what it is good it (i.e. file operations, reading, writing, etc)&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Interesting... But I'm a little afraid of getting too much into this. What if it doesn't work out and MS kills it in a release or two? (Think Exchange M: drive, Notification Services, etc)&lt;/p&gt;&lt;p&gt;Still it's pretty darn cool and helps solve a number of problems we have today...  &lt;/p&gt;&lt;p&gt;Related Past Post XRef:&lt;br /&gt;&lt;a href="http://coolthingoftheday.blogspot.com/2007/10/more-sql-server-2008-filestream-fun.html"&gt;More SQL Server 2008 FileStream Fun&lt;/a&gt;&lt;br /&gt;&lt;a href="http://coolthingoftheday.blogspot.com/2007/10/playing-with-sql-server-2008-filestream.html"&gt;Playing with the SQL Server 2008 FileStream Attribute&lt;/a&gt;&lt;/p&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/coolthingoftheday?a=az5Jf6F"&gt;&lt;img src="http://feeds.feedburner.com/~f/coolthingoftheday?i=az5Jf6F" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/coolthingoftheday?a=uKTVrUF"&gt;&lt;img src="http://feeds.feedburner.com/~f/coolthingoftheday?i=uKTVrUF" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/coolthingoftheday?a=izNilDF"&gt;&lt;img src="http://feeds.feedburner.com/~f/coolthingoftheday?i=izNilDF" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/coolthingoftheday/~4/245543571" height="1" width="1"/&gt;&lt;img alt="via softlogger.com" src="http://softlogger.com/postview.aspx?ArticleID=19953"&gt;</description><author>Gregs Cool [Insert Clever Name] of the Day</author><pubDate>2008-03-04T00:00:00</pubDate><category>Database,SQL</category></item><item><title>T-SQL Update or Insert Logic -</title><link>http://softlogger.com/19472/DatabaseSQL/t-sql-update-or-insert-logic.aspx</link><description>&lt;p&gt;&lt;a href="http://blogs.msdn.com/miah/default.aspx"&gt;Jeremiah Clark's Blog&lt;/a&gt; - &lt;a href="http://blogs.msdn.com/miah/archive/2008/02/17/sql-if-exists-update-else-insert.aspx"&gt;SQL: If Exists Update Else Insert&lt;/a&gt;&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&amp;quot;This is a pretty common situation that comes up when performing database operations.&amp;#160; A stored procedure is called and the data needs to be updated if it already exists and inserted if it does not.&amp;#160; If we refer to the Books Online documentation, it gives examples that are similar to:&lt;/p&gt;    &lt;p&gt;IF EXISTS (SELECT * FROM Table1 WHERE Column1='SomeValue')     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; UPDATE Table1 SET (...) WHERE Column1='SomeValue'      &lt;br /&gt;ELSE      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; INSERT INTO Table1 VALUES (...)&lt;/p&gt;    &lt;p&gt;This approach does work, however it might not always be the best approach. ...&lt;/p&gt;    &lt;p&gt;...&lt;/p&gt;    &lt;p&gt;UPDATE Table1 SET (...) WHERE Column1='SomeValue'     &lt;br /&gt;IF @@ROWCOUNT=0      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; INSERT INTO Table1 VALUES (...)&lt;/p&gt;    &lt;p&gt;The saved table/index scan can increase performance quite a bit as the number of rows in the targeted table grows.&lt;/p&gt;    &lt;p&gt;...&amp;quot;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Interesting... This is an approach I would not have thought of, and it's not something that I don't know I would have ever thought of. It just doesn't &amp;quot;fit&amp;quot; in my developer mind set. &lt;/p&gt;  &lt;p&gt;But now that I see it, it makes sense. It's something I'm going to have to think about and test anyway. I've got a few databases/tables with 80+ million rows, so a small improvement could lead to big results.&lt;/p&gt;  &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/coolthingoftheday?a=eaSfvTE"&gt;&lt;img src="http://feeds.feedburner.com/~f/coolthingoftheday?i=eaSfvTE" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/coolthingoftheday?a=qVbfNbE"&gt;&lt;img src="http://feeds.feedburner.com/~f/coolthingoftheday?i=qVbfNbE" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/coolthingoftheday?a=WfLBqcE"&gt;&lt;img src="http://feeds.feedburner.com/~f/coolthingoftheday?i=WfLBqcE" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/coolthingoftheday/~4/237020468" height="1" width="1"/&gt;&lt;img alt="via softlogger.com" src="http://softlogger.com/postview.aspx?ArticleID=19472"&gt;</description><author>Gregs Cool [Insert Clever Name] of the Day</author><pubDate>2008-02-20T00:00:00</pubDate><category>Database,SQL</category></item><item><title>Building an N-Layer ASP.NET Application with LINQ, Lambdas and Stored Procedures</title><link>http://softlogger.com/19518/DatabaseSQL/building-an-n-layer-asp-net-application-with-linq-lambdas-and-stored-procedures.aspx</link><description>&lt;P&gt;.NET 3.5 has a lot of great new features that can significantly enhance developer productivity.&amp;nbsp; I've been spending some time lately working on a little sample application that demonstrates how an N-Layer ASP.NET 3.5 application can be built using LINQ, lambdas and LINQ with stored procedures.&amp;nbsp; The application is for a talk I'll be giving at &lt;A href="http://www.devconnections.com/" target=_blank mce_href="http://www.devconnections.com"&gt;DevConnections&lt;/A&gt; in April discussing how LINQ technologies can be used in an N-Layer architecture.&amp;nbsp; In a &lt;A href="http://weblogs.asp.net/dwahlin/archive/2008/02/17/linq-and-lambdas-and-sprocs-oh-my.aspx" target=_blank mce_href="http://weblogs.asp.net/dwahlin/archive/2008/02/17/linq-and-lambdas-and-sprocs-oh-my.aspx"&gt;previous post&lt;/A&gt; comparing different LINQ options I mentioned that I'd be posting the code download as soon as it was ready.&amp;nbsp; You can now &lt;A href="http://www.xmlforasp.net/CodeBank/Download/Blog/N-Layer_WithLINQ.zip" mce_href="http://www.xmlforasp.net/CodeBank/Download/Blog/N-Layer_WithLINQ.zip"&gt;download it here&lt;/A&gt; if you're interested.&lt;/P&gt;
&lt;P&gt;The application provides a presentation layer, business layer, data layer and model layer through separate projects as shown next:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://weblogs.asp.net/blogs/dwahlin/WindowsLiveWriter/BuildinganNLayerA.NETApplicationwithLINQ_963D/image_2.png" mce_href="http://weblogs.asp.net/blogs/dwahlin/WindowsLiveWriter/BuildinganNLayerA.NETApplicationwithLINQ_963D/image_2.png"&gt;&lt;IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=476 alt=image src="http://weblogs.asp.net/blogs/dwahlin/WindowsLiveWriter/BuildinganNLayerA.NETApplicationwithLINQ_963D/image_thumb.png" width=199 border=0 mce_src="http://weblogs.asp.net/blogs/dwahlin/WindowsLiveWriter/BuildinganNLayerA.NETApplicationwithLINQ_963D/image_thumb.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;It also demonstrates how the new ListView control can be used to display data, perform insert, update and delete operations and nest other controls such as the GridView.&amp;nbsp; Databinding on the presentation layer is mainly done using the ObjectDataSource control.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://weblogs.asp.net/blogs/dwahlin/WindowsLiveWriter/BuildinganNLayerA.NETApplicationwithLINQ_963D/image_4.png" mce_href="http://weblogs.asp.net/blogs/dwahlin/WindowsLiveWriter/BuildinganNLayerA.NETApplicationwithLINQ_963D/image_4.png"&gt;&lt;IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=400 alt="Application Example" src="http://weblogs.asp.net/blogs/dwahlin/WindowsLiveWriter/BuildinganNLayerA.NETApplicationwithLINQ_963D/image_thumb_1.png" width=532 border=0 mce_src="http://weblogs.asp.net/blogs/dwahlin/WindowsLiveWriter/BuildinganNLayerA.NETApplicationwithLINQ_963D/image_thumb_1.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;All of the queries performed in the application go against an object model created using the Visual Studio 2008 LINQ to SQL Designer.&amp;nbsp; &lt;BR&gt;&lt;BR&gt;&lt;FONT color=#ff0000&gt;&lt;STRONG&gt;Note:&lt;/STRONG&gt;&lt;/FONT&gt;&amp;nbsp; The included Northwind SQL Express database has been modified slightly to add a TimeStamp field into the Customer and Orders tables and contains several custom stored procedures (sprocs aren't required unless using that portion of the application).&amp;nbsp; Adding TimeStamp fields&amp;nbsp;simplifies updates so be aware that if you change the connection string to point to a standard Northwind database you'll get an error since the TimeStamp fields will be missing.&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://weblogs.asp.net/blogs/dwahlin/WindowsLiveWriter/LINQandLambdasandSprocs.OhMy_89C7/image_2.png" mce_src="http://weblogs.asp.net/blogs/dwahlin/WindowsLiveWriter/LINQandLambdasandSprocs.OhMy_89C7/image_2.png"&gt; &lt;/P&gt;
&lt;H2&gt;&lt;BR&gt;3 Options for Data Access&lt;/H2&gt;
&lt;P&gt;Rather than focusing solely on LINQ, I wanted to show different options for data access that .NET 3.5 offers so that developers can get a feel for what's available in addition to standard LINQ queries that seem to get most of the attention these days.&amp;nbsp; I ended up creating six main data layer classes as shown next: &lt;BR&gt;&lt;BR&gt;&lt;STRONG&gt;Customer Query Classes:&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;CustomerDBLINQ - Executes customer related queries using inline LINQ &lt;/LI&gt;
&lt;LI&gt;CustomerDBLambda - Executes customer related queries using lambda expressions &lt;/LI&gt;
&lt;LI&gt;CustomerDBSprocs - Executes customer related queries using stored procedures and LINQ &lt;BR&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;STRONG&gt;Order Query Classes:&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;OrderDBLINQ - Executes order related queries using inline LINQ &lt;/LI&gt;
&lt;LI&gt;OrderDBLambda - Executes order related queries using lambda expressions &lt;/LI&gt;
&lt;LI&gt;OrderDBSprocs - Executes order related queries using stored procedures and LINQ &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;I still lean toward using stored procedures due to the security and maintenance benefits they offer in more enterprise environments, but for small queries I actually prefer lambda expressions over LINQ (not sure why...just feels more object oriented I guess).&amp;nbsp; If you currently use stored procedures in your applications and haven't checked out the new LINQ to SQL Designer you'll be impressed with how easy it is to call stored procedures and pass parameters.&amp;nbsp; You never have to see or create another SqlCommand or SqlParameter object again (well...in many cases anyway).&lt;/P&gt;
&lt;H2&gt;&lt;BR&gt;Switching Between Data Access Classes&lt;/H2&gt;
&lt;P&gt;By changing a value in web.config you can switch between the different data layer classes and see which option you prefer (LINQ, lambdas or LINQ with sprocs).&amp;nbsp; All of the data access classes perform the same overall tasks, they just use different techniques to do it.&lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;appSettings&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
  &amp;lt;!-- 
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;Used to define which DB layer class should be loaded and used. 
    Valid customer values include:  Data.CustomerDBSprocs, Data.CustomerLINQ, Data.CustomerLambda
    Valid order values include: Data.OrderDBSprocs, Data.OrderLINQ, Data.OrderLambda
  &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;--&amp;gt;
  &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;add &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;key&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;CustomerDBType&lt;/SPAN&gt;" &lt;SPAN style="COLOR: red"&gt;value&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;Data.CustomerDBLINQ&lt;/SPAN&gt;" &lt;SPAN style="COLOR: blue"&gt;/&amp;gt;
  &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;add &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;key&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;OrderDBType&lt;/SPAN&gt;" &lt;SPAN style="COLOR: red"&gt;value&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;Data.OrderDBLINQ&lt;/SPAN&gt;" &lt;SPAN style="COLOR: blue"&gt;/&amp;gt;
  &amp;lt;!-- &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;When the following key is set to "true" ensure that &lt;BR&gt;       &lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;EnablePartialRendering is set to false on the Default.aspx ScriptManager control &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;--&amp;gt;
  &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;add &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;key&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;EnableDataContextLogging&lt;/SPAN&gt;" &lt;SPAN style="COLOR: red"&gt;value&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;false&lt;/SPAN&gt;" &lt;SPAN style="COLOR: blue"&gt;/&amp;gt;
&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;appSettings&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;Over the next few weeks I'm hoping to make some time to walk through the application pieces.&amp;nbsp; I may create some video tutorials about it as well....we'll see how time goes.&lt;/P&gt;
&lt;DIV class=wlWriterSmartContent id=scid:0767317B-992E-4b12-91E0-4F059A8CECA8:ad64d0f8-6190-4c01-b201-ded34dd0d5b4 style="PADDING-RIGHT: 0px; DISPLAY: inline; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px"&gt;del.icio.us Tags: &lt;A href="http://del.icio.us/popular/N-Layer" rel=tag&gt;N-Layer&lt;/A&gt;,&lt;A href="http://del.icio.us/popular/LINQ" rel=tag&gt;LINQ&lt;/A&gt;,&lt;A href="http://del.icio.us/popular/Lambdas" rel=tag&gt;Lambdas&lt;/A&gt;,&lt;A href="http://del.icio.us/popular/Stored%20Procedures" rel=tag&gt;Stored Procedures&lt;/A&gt;,&lt;A href="http://del.icio.us/popular/ListView" rel=tag&gt;ListView&lt;/A&gt;,&lt;A href="http://del.icio.us/popular/ASP.NET" rel=tag&gt;ASP.NET&lt;/A&gt;&lt;/DIV&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5817073" width="1" height="1"&gt;&lt;img alt="via softlogger.com" src="http://softlogger.com/postview.aspx?ArticleID=19518"&gt;</description><author>Dan Wahlins WebLog</author><pubDate>2008-02-19T00:00:00</pubDate><category>Database,SQL</category></item><item><title>High Performance LINQ To SQL - Compiled Queries - O/R Mappers - Ecommerce Websites</title><link>http://softlogger.com/19440/DatabaseSQL/high-performance-linq-to-sql--compiled-queries--o-r-mappers--ecommerce-websites.aspx</link><description>&lt;H1&gt;&lt;FONT face=Verdana&gt;High Performance LINQ To SQL - Compiled Queries - O/R Mappers - Ecommerce Websites&lt;/FONT&gt;&lt;/H1&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;by &lt;A href="http://www.davidhayden.com/"&gt;David Hayden&lt;/A&gt;, &lt;A href="http://www.davidhayden.com/"&gt;Florida ASP.NET Developer&lt;/A&gt;, Filed: &lt;A href="http://davidhayden.com/blog/dave/category/59.aspx?Show=All"&gt;LINQ To SQL&lt;/A&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;It should be of no surprise that an &lt;A href="http://davidhayden.com/blog/dave/category/24.aspx?Show=All"&gt;O/R Mapper&lt;/A&gt; will add overhead to performance as compared to the performance one would receive from a DataReader in ADO.NET. LINQ To SQL is no different. It adds a lot of services on top of ADO.NET, such as:&lt;/FONT&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;Connection&amp;nbsp; Management&lt;/FONT&gt; 
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;Query Translation and Execution&lt;/FONT&gt; 
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;Object Identity&lt;/FONT&gt; 
&lt;LI&gt;&lt;FONT face=Verdana size=2&gt;Change Tracking&lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;This, of course, all comes at a little bit of a performance overhead. For most applications and user stories the&amp;nbsp;slower performance&amp;nbsp;is irrelevant. The value of the O/R Mapping services greatly outweigh any degradation in performance.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Sometimes, however, there may be a couple of database activities that are very expensive and we may want to achieve as optimal performance as possible even at the expense of maintainability. LINQ To SQL has a solution for these times - &lt;STRONG&gt;Compiled Queries&lt;/STRONG&gt;.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;H2&gt;&lt;FONT face=Verdana&gt;LINQ To SQL Compiled Queries&lt;/FONT&gt;&lt;/H2&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Let's pretend we have an &lt;STRONG&gt;e-commerce website&lt;/STRONG&gt; and getting Products By Category is an expensive operation. We have optimized the database as much as we can using proper indexing and covering indexes and it just isn't enough. We are using LINQ To SQL and we decide it is time for Compiled Queries. LINQ To SQL Compiled Queries allow the translation of the query to happen once at compile time and the query to be consumed many times. The lack of translation at each call will greatly improve performance for our e-commerce store.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Using Northwind, I create a partial class of the &lt;STRONG&gt;NorthwindDataContext&lt;/STRONG&gt; and add my compiled query:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;FONT color=#0000ff&gt;partial&lt;/FONT&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;class&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; NorthwindDataContext
{
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;static&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; Func&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;NorthwindDataContext, &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;int&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;, IQueryable&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;Product&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;&amp;gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
        ProductsByCategoryID &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;FONT color=#ff0000&gt;CompiledQuery&lt;/FONT&gt;.&lt;FONT color=#ff0000&gt;Compile&lt;/FONT&gt;
            ((NorthwindDataContext context, &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;int&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; categoryID) &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;
            context.Products.Where(p &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; p.CategoryID &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;==&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; categoryID));

    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; IQueryable&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;Product&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; GetProductsByCategoryIDFast(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;int&lt;BR&gt;                                                        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;categoryID)
    {
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; ProductsByCategoryID(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;this&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;, categoryID);
    }
}&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Everything above is compiled except for the category I am searching on. Note we are using &lt;A href="http://davidhayden.com/blog/dave/archive/2006/12/18/ExpressionTrees.aspx"&gt;Expression Trees&lt;/A&gt;, which are new to &lt;A href="http://davidhayden.com/blog/dave/archive/2006/12/21/QueryExpressionsAnonymousTypesLambaExpressions.aspx"&gt;C# 3.0&lt;/A&gt;. This will greatly improve the performance of getting the products by category in my e-commerce store.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Now in my e-commerce website I will use the higher performance method of accessing the products in my product catalog by category:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: #000000"&gt;NorthwindDataContext db &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; NorthwindDataContext();

List&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;Product&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; products &lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; db.GetProductsByCategoryIDFast(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;1&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;).ToList();&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Here I am getting all the products in my product catalog&amp;nbsp;in the CategoryID = 1. The improvement in performance is much better and very close to the performance of the speed of the DataReader in ADO.NET. This should make my e-commerce website perform much quicker than when not using a LINQ To SQL Compiled Query.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;For more information on the performance one achieves by using LINQ To SQL Compiled Queries, I recommend reading Rico Mariana's blog:&lt;/FONT&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/ricom/archive/2007/06/22/dlinq-linq-to-sql-performance-part-1.aspx" target=_blank&gt;&lt;FONT face=Verdana size=2&gt;http://blogs.msdn.com/ricom/archive/2007/06/22/dlinq-linq-to-sql-performance-part-1.aspx&lt;/FONT&gt;&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;There are actually several parts to his LINQ To SQL performance testing that you can read on his blog.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;H2&gt;&lt;FONT face=Verdana&gt;Conclusion&lt;/FONT&gt;&lt;/H2&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;LINQ To SQL offers the option of Compiled Queries when you need to achieve DataReader like performances in ADO.NET. This comes at a bit of a price of maintenance, because you will need to create compiled queries for those operations you feel are expensive.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;H2&gt;&lt;FONT face=Verdana&gt;LINQ To SQL Tutorials&lt;/FONT&gt;&lt;/H2&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2008/01/01/ASPNETDynamicDataValidationLINQToSQLOnPropertyChangingPartialMethods.aspx"&gt;&lt;FONT face=Verdana color=#0000ff size=2&gt;ASP.NET Dynamic Data and Validation Using LINQ To SQL OnPropertyChanging Partial Methods&lt;/FONT&gt;&lt;/A&gt; 
&lt;LI&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2007/10/28/LINQToSQLEnumSupportExampleDiscriminatorColumnInheritanceMapping.aspx"&gt;&lt;FONT face=Verdana color=#0000ff size=2&gt;LINQ To SQL Enum Support Example Using Discriminator Column and Inheritance Mapping&lt;/FONT&gt;&lt;/A&gt; 
&lt;LI&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2007/10/26/LINQToSQLInheritanceDiscriminatorColumnExampleInheritanceMappingTutorial.aspx"&gt;&lt;FONT face=Verdana color=#0000ff size=2&gt;LINQ To SQL Discriminator Column Example - Inheritance Mapping Tutorial&lt;/FONT&gt;&lt;/A&gt; 
&lt;LI&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2007/10/12/LINQToSQLAttachMethodAttachingDetachedBusinessEntitiesDataContextAttach.aspx"&gt;&lt;FONT face=Verdana color=#0000ff size=2&gt;LINQ To SQL Attach Method for Attaching Detached Business Entities - DataContext.Attach&lt;/FONT&gt;&lt;/A&gt; 
&lt;LI&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2007/09/28/LINQToSQLVisualStudio2008PerformanceUpdate.aspx"&gt;&lt;FONT face=Verdana size=2&gt;LINQ To SQL and Visual Studio 2008 Performance Update&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; &lt;/FONT&gt;
&lt;LI&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2007/09/23/LINQPadDynamicallyQuerySQLDatabasesLINQ.aspx"&gt;&lt;FONT face=Verdana color=#0000ff size=2&gt;LINQPad - Dynamically Query SQL Server Databases in LINQ&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; &lt;/FONT&gt;
&lt;LI&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2007/08/20/LINQToSQLDebuggerVisualizerRevisitedSameConcernsBetterUI.aspx"&gt;&lt;FONT face=Verdana color=#0000ff size=2&gt;LINQ To SQL Debugger Visualizer Revisited - Same Concerns Better UI :)&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; &lt;/FONT&gt;
&lt;LI&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2007/08/17/DataContextLogLoggingLINQToSQLOutputConsoleDebuggerOuputWindow.aspx"&gt;&lt;FONT face=Verdana color=#0000ff size=2&gt;DataContext.Log - Logging LINQ To SQL Output to Console or Debugger Output Window&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; &lt;/FONT&gt;
&lt;LI&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2007/08/17/LINQToSQLDebuggerVisualizerVisualStudio2008HasLimitedValueLINQToSQLTutorials.aspx"&gt;&lt;FONT face=Verdana color=#0000ff size=2&gt;LINQ To SQL Debugger Visualizer in Visual Studio 2008 Has Limited Value - LINQ To SQL Tutorials&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; &lt;/FONT&gt;
&lt;LI&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2007/08/09/LINQToSQLReplacementDataAccessGuidancePackage.aspx"&gt;&lt;FONT face=Verdana color=#0000ff size=2&gt;LINQ To SQL As Replacement To Data Access Guidance Package&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; &lt;/FONT&gt;
&lt;LI&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2007/08/08/LINQDataAccessLayerCreatingInsertUpdateDeleteStoredProcedures.aspx"&gt;&lt;FONT face=Verdana color=#0000ff size=2&gt;LINQ Data Access Layer - Creating Insert Update Delete Stored Procedures&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; &lt;/FONT&gt;
&lt;LI&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2007/08/07/CreatingDataAccessLayerLINQToSQLStoredProceduresSupport.aspx"&gt;&lt;FONT face=Verdana color=#0000ff size=2&gt;Creating Data Access Layer Using LINQ To SQL - Stored Procedures Support&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; &lt;/FONT&gt;
&lt;LI&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2007/08/03/LinqDataSourceHighPerformanceQueriesDataLoadOptionsAvoidingDatabaseRoundtrips.aspx"&gt;&lt;FONT face=Verdana color=#0000ff size=2&gt;LinqDataSource - High Performance Queries Using DataLoadOptions - Avoiding Database Roundtrips&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; &lt;/FONT&gt;
&lt;LI&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2007/08/05/LINQToSQLPerformanceTradeoffsLessDatabaseRoundtripsButDuplicatedData.aspx"&gt;&lt;FONT face=Verdana color=#0000ff size=2&gt;LINQ to SQL - Performance Tradeoffs: Less Database Roundtrips but Duplicated Data in Each Row??&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; &lt;/FONT&gt;
&lt;LI&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2007/08/05/LINQToSQLLazyLoadingPropertiesSpecifyingPreFetchWhenNeededPerformance.aspx"&gt;&lt;FONT face=Verdana color=#0000ff size=2&gt;LINQ To SQL - Lazy Loading Properties and Specifying PreFetch When Needed - Sweet Query and Performance Control&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt; &lt;/FONT&gt;
&lt;LI&gt;&lt;A href="http://davidhayden.com/blog/dave/archive/2007/08/06/LINQToSQLVideoGettingFromExpressionTreesToSQL.aspx"&gt;&lt;FONT face=Verdana color=#0000ff size=2&gt;LINQ To SQL Video - Getting From Expression Trees to SQL&lt;/FONT&gt;&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Author:&amp;nbsp;&lt;/FONT&gt;&lt;A href="http://www.davidhayden.com/"&gt;&lt;FONT face=Verdana size=2&gt;David Hayden&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Verdana size=2&gt;, &lt;/FONT&gt;&lt;A href="http://www.davidhayden.com/"&gt;&lt;FONT face=Verdana size=2&gt;Florida&amp;nbsp;Website Developer&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;Site: &lt;/FONT&gt;&lt;A href="http://www.davidhayden.com/"&gt;&lt;FONT face=Verdana size=2&gt;http://www.davidhayden.com/&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Verdana size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;&lt;img src ="http://davidhayden.com/blog/dave/aggbug/3464.aspx" width = "1" height = "1" /&gt;&lt;img alt="via softlogger.com" src="http://softlogger.com/postview.aspx?ArticleID=19440"&gt;</description><author>David Hayden - Florida .NET Developer - C# and SQL Server</author><pubDate>2008-02-19T00:00:00</pubDate><category>Database,SQL</category></item><item><title>Debugging Custom Actions: Leaked Handles</title><link>http://softlogger.com/18932/DatabaseSQL/debugging-custom-actions-leaked-handles.aspx</link><description>&lt;p&gt;&lt;a href="http://msdn2.microsoft.com/library/aa368264.aspx"&gt;Debugging custom actions&lt;/a&gt; isn't exactly the easiest action to do; Windows Installer spawns separate processes - remoting servers - to run in-process custom actions. Any opportunity to diagnose issues without debugging can be helpful.&lt;/p&gt; &lt;p&gt;For example, an issue that comes up from time to time is leaked handles. A Windows Installer debug log might show something similar to the following:&lt;/p&gt; &lt;p&gt;&lt;code&gt;MSI (s) (CC:1C) [17:40:29:055]: Doing action: MyCustomAction&lt;br&gt;MSI (s) (CC:58) [17:40:29:165]: Invoking remote custom action. DLL: C:\WINDOWS\Installer\MSI1B.tmp, Entrypoint: MyCustomAction&lt;br&gt;Action start 17:40:29: MyCustomAction.&lt;br&gt;MSI (s) (CC:58) [17:40:29:906]: &lt;span class="highligh" style="background-color: yellow"&gt;Leaked MSIHANDLE (219) of type 790531&lt;/span&gt; for thread 3676&lt;br&gt;MSI (s) (CC:58) [17:40:29:906]: &lt;span class="highligh" style="background-color: yellow"&gt;Leaked MSIHANDLE (190) of type 790540&lt;/span&gt; for thread 3676&lt;br&gt;MSI (s) (CC:58) [17:40:29:906]: &lt;span class="highligh" style="background-color: yellow"&gt;Leaked MSIHANDLE (189) of type 790540&lt;/span&gt; for thread 3676&lt;br&gt;MSI (s) (CC:58) [17:40:29:906]: &lt;span class="highligh" style="background-color: yellow"&gt;Leaked MSIHANDLE (188) of type 790540&lt;/span&gt; for thread 3676&lt;br&gt;MSI (s) (CC:58) [17:40:29:906]: &lt;span class="highligh" style="background-color: yellow"&gt;Leaked MSIHANDLE (179) of type 790541&lt;/span&gt; for thread 3676&lt;br&gt;MSI (s) (CC:58) [17:40:29:906]: Note: 1: 2769 2: MyCustomAction 3: 5 &lt;br&gt;DEBUG: Error 2769: Custom Action MyCustomAction did not close 5 &lt;br&gt;Action ended 17:40:30: MyCustomAction. Return value 3.&lt;/code&gt;&lt;/p&gt; &lt;p&gt;Windows Installer provides a clue in the log that can help with a code review. The Windows Installer team has provided the following information:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;MSIHANDLE type 790531 identifies a record  &lt;li&gt;MSIHANDLE type 790540 identifies a view  &lt;li&gt;MSIHANDLE type 790541 identifies a database&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;With this knowledge, you should be able to review your code and spot cause of the issue.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=7652939" width="1" height="1"&gt;&lt;img alt="via softlogger.com" src="http://softlogger.com/postview.aspx?ArticleID=18932"&gt;</description><author>Heath Stewarts Blog</author><pubDate>2008-02-12T00:00:00</pubDate><category>Database,SQL</category></item><item><title>Being IN in LINQ to SQL - Or How I learned to Love Contains (aka Getting Linq to SQL to generate a T-SQL WHERE clause that includes an IN)</title><link>http://softlogger.com/18590/DatabaseSQL/being-in-in-linq-to-sql--or-how-i-learned-to-love-contains-aka-getting-linq-to-sql-to-generate-a-t-sql-where-clause-that-includes-an-in.aspx</link><description>&lt;p&gt;So today was my first time really playing with Linq to SQL (or any flavor of Linq for that matter). I'm prototyping a new feature and wanted to see how Linq could help... &lt;/p&gt; &lt;p&gt;The biggest road block? Trying to figure out how to do a IN in Linq to SQL, i.e. SELECT * FROM table WHERE column IN ('value','another','etc')&lt;/p&gt; &lt;p&gt;Dynamically building OR's wasn't going to cut it. (Linq: ... WHERE C.Column = "Value" or C.Column = "another" or C.Column = "etc" ) &lt;/p&gt; &lt;p&gt;And using a Lambda expression in the Linq Where was making my brain hurt. &lt;/p&gt; &lt;p&gt;There had to be a simple and easy way to do this...&lt;/p&gt; &lt;p&gt;Luckily through the power of the search I found a hint for a truly workable and clean solution. One that results in final SQL that includes an IN. &lt;a href="http://www.develop-one.net/blog/default.aspx"&gt;The Blomsma Code&lt;/a&gt; - &lt;a href="http://www.develop-one.net/blog/2007/11/11/LINQToSQLJoiningDatabaseDataWithNondatabaseData.aspx"&gt;LINQ to SQL: Joining database data with non-database data&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;The magic is with the Contains and to turn the Where on its head. &lt;/p&gt; &lt;p&gt;Here's an example (see the screenshots below).&amp;nbsp; The code pretty much speaks for itself. &lt;/p&gt; &lt;p&gt;The key is the order in the Where clause. I kept looking for an another method, another way, a more T-SQL kind of thing. Some way to say emp.Country IN bla bla or emp.Country.Contains(bla, bla), etc. But nothing would work or result in an IN based SQL Query... That is until I found the hint I needed in the above post.&lt;/p&gt; &lt;p&gt;Now the below code works exactly as I wanted. It builds a T-SQL statement using IN in the WHERE clause, is clean, scalable and easy to understand...&lt;/p&gt; &lt;p&gt;The source code and project is also available here, &lt;a title="http://code.msdn.microsoft.com/LinqtoSQLJoinExample" href="http://code.msdn.microsoft.com/LinqtoSQLJoinExample"&gt;http://code.msdn.microsoft.com/LinqtoSQLJoinExample&lt;/a&gt; (but it's all below too... Yep, that's it, that's all of it... )&lt;/p&gt; &lt;h3&gt;Source&lt;/h3&gt;&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;Imports &lt;/span&gt;System.Data.Linq&lt;br&gt;&lt;span style="color: blue"&gt;Imports &lt;/span&gt;System.Data.SqlClient&lt;br&gt;&lt;br&gt;&lt;span style="color: blue"&gt;Public Class &lt;/span&gt;Form1&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;  &lt;span style="color: blue"&gt;Private Sub &lt;/span&gt;Button1_Click(&lt;span style="color: blue"&gt;ByVal &lt;/span&gt;sender &lt;span style="color: blue"&gt;As &lt;/span&gt;System.Object, &lt;span style="color: blue"&gt;ByVal &lt;/span&gt;e &lt;span style="color: blue"&gt;As &lt;/span&gt;System.EventArgs) &lt;span style="color: blue"&gt;Handles &lt;/span&gt;Button1.Click&lt;br&gt;&lt;/pre&gt;&lt;pre class="code"&gt;    &lt;span style="color: blue"&gt;Dim &lt;/span&gt;db &lt;span style="color: blue"&gt;As New &lt;/span&gt;Northwind(&lt;span style="color: #a31515"&gt;"Data Source=C:\Program Files\Microsoft SQL Server Compact Edition\v3.5\Samples\Northwind.sdf"&lt;/span&gt;)&lt;br&gt;&lt;/pre&gt;&lt;pre class="code"&gt;    &lt;span style="color: blue"&gt;Dim &lt;/span&gt;Countries() &lt;span style="color: blue"&gt;As String &lt;/span&gt;= &lt;span style="color: blue"&gt;Me&lt;/span&gt;.TextBox1.Text.Split(&lt;span style="color: #a31515"&gt;","c&lt;/span&gt;)&lt;br&gt;&lt;/pre&gt;&lt;pre class="code"&gt;    &lt;span style="color: blue"&gt;Dim &lt;/span&gt;query = &lt;span style="color: blue"&gt;From &lt;/span&gt;emp &lt;span style="color: blue"&gt;In &lt;/span&gt;db.Employees _&lt;br&gt;                &lt;span style="color: blue"&gt;Where &lt;/span&gt;Countries.Contains(emp.Country) _&lt;br&gt;                &lt;span style="color: blue"&gt;Select &lt;/span&gt;emp&lt;br&gt;&lt;/pre&gt;&lt;pre class="code"&gt;    db.Log = Console.Out&lt;br&gt;&lt;/pre&gt;&lt;pre class="code"&gt;    &lt;span style="color: blue"&gt;Me&lt;/span&gt;.DataGridView1.DataSource = query&lt;br&gt;&lt;/pre&gt;&lt;pre class="code"&gt;  &lt;span style="color: blue"&gt;End Sub&lt;br&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;End Class&lt;br&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;&lt;h3&gt;Screenshots&lt;/h3&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://lh5.google.com/gduncan411/R5qPfMYyCOI/AAAAAAAAAL0/LTs6jhhV6s8/image%5B4%5D"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="180" alt="image" src="http://lh3.google.com/gduncan411/R5qPfsYyCPI/AAAAAAAAAL8/h6BoaYwoUHc/image_thumb%5B2%5D" width="644" border="0"&gt;&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://lh5.google.com/gduncan411/R5qPgMYyCQI/AAAAAAAAAME/pY2Iwef1PPc/image%5B11%5D"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="180" alt="image" src="http://lh3.google.com/gduncan411/R5qPgsYyCRI/AAAAAAAAAMM/DQ6IadN3m6o/image_thumb%5B5%5D" width="644" border="0"&gt;&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://lh6.google.com/gduncan411/R5qPhcYyCSI/AAAAAAAAAMU/acz_ZfWBWM0/image%5B12%5D"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="180" alt="image" src="http://lh4.google.com/gduncan411/R5qPh8YyCTI/AAAAAAAAAMg/Uc97PzOzmME/image_thumb%5B6%5D" width="644" border="0"&gt;&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://lh3.google.com/gduncan411/R5qPisYyCUI/AAAAAAAAAMo/5MiU2XAahAQ/image%5B19%5D"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="243" alt="image" src="http://lh5.google.com/gduncan411/R5qPjMYyCVI/AAAAAAAAAMw/BHimAV0b8HY/image_thumb%5B11%5D" width="644" border="0"&gt;&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://lh4.google.com/gduncan411/R5qPj8YyCWI/AAAAAAAAAM4/keZqSs6BzPA/image%5B27%5D"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="270" alt="image" src="http://lh3.google.com/gduncan411/R5qPksYyCXI/AAAAAAAAANA/safRpK6fO3I/image_thumb%5B17%5D" width="644" border="0"&gt;&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;h3&gt;T-SQL Generated by Linq to SQL&lt;/h3&gt;&lt;br /&gt;&lt;p&gt;SELECT [t0].[Employee ID] AS [EmployeeID], [t0].[Last Name] AS [LastName], [t0].[First Name] AS [FirstName], [t0].[Title], [t0].[Birth Date] AS [BirthDate], [t0].[Hire Date] AS [HireDate], [t0].[Address], [t0].[City], [t0].[Region], [t0].[Postal Code] AS [PostalCode], [t0].[Country], [t0].[Home Phone] AS [HomePhone], [t0].[Extension], [t0].[Photo], [t0].[Notes], [t0].[Reports To] AS [ReportsTo]&lt;br&gt;FROM [Employees] AS [t0]&lt;br&gt;WHERE [t0].[Country] IN (@p0)&lt;br&gt;-- @p0: Input String (Size = 0; Prec = 0; Scale = 0) [USA]&lt;br&gt;-- Context: SqlProvider(SqlCE) Model: AttributedMetaModel Build: 3.5.21022.8 &lt;/p&gt;&lt;br&gt;&lt;br /&gt;&lt;p&gt;SELECT [t0].[Employee ID] AS [EmployeeID], [t0].[Last Name] AS [LastName], [t0].[First Name] AS [FirstName], [t0].[Title], [t0].[Birth Date] AS [BirthDate], [t0].[Hire Date] AS [HireDate], [t0].[Address], [t0].[City], [t0].[Region], [t0].[Postal Code] AS [PostalCode], [t0].[Country], [t0].[Home Phone] AS [HomePhone], [t0].[Extension], [t0].[Photo], [t0].[Notes], [t0].[Reports To] AS [ReportsTo]&lt;br&gt;FROM [Employees] AS [t0]&lt;br&gt;WHERE [t0].[Country] IN (@p0, @p1)&lt;br&gt;-- @p0: Input String (Size = 0; Prec = 0; Scale = 0) [USA]&lt;br&gt;-- @p1: Input String (Size = 0; Prec = 0; Scale = 0) [UK]&lt;br&gt;-- Context: SqlProvider(SqlCE) Model: AttributedMetaModel Build: 3.5.21022.8 &lt;/p&gt;&lt;br&gt;&lt;br /&gt;&lt;p&gt;SELECT [t0].[Employee ID] AS [EmployeeID], [t0].[Last Name] AS [LastName], [t0].[First Name] AS [FirstName], [t0].[Title], [t0].[Birth Date] AS [BirthDate], [t0].[Hire Date] AS [HireDate], [t0].[Address], [t0].[City], [t0].[Region], [t0].[Postal Code] AS [PostalCode], [t0].[Country], [t0].[Home Phone] AS [HomePhone], [t0].[Extension], [t0].[Photo], [t0].[Notes], [t0].[Reports To] AS [ReportsTo]&lt;br&gt;FROM [Employees] AS [t0]&lt;br&gt;WHERE [t0].[Country] IN (@p0)&lt;br&gt;-- @p0: Input String (Size = 0; Prec = 0; Scale = 0) [UK]&lt;br&gt;-- Context: SqlProvider(SqlCE) Model: AttributedMetaModel Build: 3.5.21022.8&lt;/p&gt;&lt;br&gt;&lt;br /&gt;&lt;p&gt;SELECT [t0].[Employee ID] AS [EmployeeID], [t0].[Last Name] AS [LastName], [t0].[First Name] AS [FirstName], [t0].[Title], [t0].[Birth Date] AS [BirthDate], [t0].[Hire Date] AS [HireDate], [t0].[Address], [t0].[City], [t0].[Region], [t0].[Postal Code] AS [PostalCode], [t0].[Country], [t0].[Home Phone] AS [HomePhone], [t0].[Extension], [t0].[Photo], [t0].[Notes], [t0].[Reports To] AS [ReportsTo]&lt;br&gt;FROM [Employees] AS [t0]&lt;br&gt;WHERE [t0].[Country] IN (@p0, @p1)&lt;br&gt;-- @p0: Input String (Size = 0; Prec = 0; Scale = 0) [France]&lt;br&gt;-- @p1: Input String (Size = 0; Prec = 0; Scale = 0) [UK]&lt;br&gt;-- Context: SqlProvider(SqlCE) Model: AttributedMetaModel Build: 3.5.21022.8 &lt;/p&gt;&lt;br&gt;&lt;br /&gt;&lt;p&gt;SELECT [t0].[Employee ID] AS [EmployeeID], [t0].[Last Name] AS [LastName], [t0].[First Name] AS [FirstName], [t0].[Title], [t0].[Birth Date] AS [BirthDate], [t0].[Hire Date] AS [HireDate], [t0].[Address], [t0].[City], [t0].[Region], [t0].[Postal Code] AS [PostalCode], [t0].[Country], [t0].[Home Phone] AS [HomePhone], [t0].[Extension], [t0].[Photo], [t0].[Notes], [t0].[Reports To] AS [ReportsTo]&lt;br&gt;FROM [Employees] AS [t0]&lt;br&gt;WHERE [t0].[Country] IN (@p0, @p1, @p2)&lt;br&gt;-- @p0: Input String (Size = 0; Prec = 0; Scale = 0) [France]&lt;br&gt;-- @p1: Input String (Size = 0; Prec = 0; Scale = 0) [UK]&lt;br&gt;-- @p2: Input String (Size = 0; Prec = 0; Scale = 0) [USA]&lt;br&gt;-- Context: SqlProvider(SqlCE) Model: AttributedMetaModel Build: 3.5.21022.8 &lt;/p&gt;  &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~f/coolthingoftheday?a=MJ0M74D"&gt;&lt;img src="http://feeds.feedburner.com/~f/coolthingoftheday?i=MJ0M74D" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/coolthingoftheday?a=rbCylbD"&gt;&lt;img src="http://feeds.feedburner.com/~f/coolthingoftheday?i=rbCylbD" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~f/coolthingoftheday?a=nlPPKPD"&gt;&lt;img src="http://feeds.feedburner.com/~f/coolthingoftheday?i=nlPPKPD" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/coolthingoftheday/~4/223255652" height="1" width="1"/&gt;&lt;img alt="via softlogger.com" src="http://softlogger.com/postview.aspx?ArticleID=18590"&gt;</description><author>Gregs Cool [Insert Clever Name] of the Day</author><pubDate>2008-01-30T00:00:00</pubDate><category>Database,SQL</category></item><item><title>Maintaining Unique Indexes with IGNORE_DUP_KEY</title><link>http://softlogger.com/18625/DatabaseSQL/maintaining-unique-indexes-with-ignore_dup_key.aspx</link><description>&lt;P&gt;A few months ago, I wrote a post describing &lt;A title="Maintaining Unique Indexes" href="http://blogs.msdn.com/craigfr/archive/2007/09/06/maintaining-unique-indexes.aspx"&gt;how SQL Server maintains unique indexes&lt;/A&gt; while avoiding false uniqueness violations.&amp;nbsp; In this post, I'm going to look at how SQL Server maintains unique indexes that were created with the WITH IGNORE_DUP_KEY clause.&amp;nbsp; Normally, if we attempt to insert a duplicate key into a unique index, SQL Server fails the entire statement, rolls back any changes made by that statement, and returns an error.&amp;nbsp; However, if we attempt to insert a duplicate key into a unique index that was created with the WITH IGNORE_DUP_KEY clause, SQL Server merely discards the "bad" row, generates a warning message, and continues executing the remainder of the statement.&amp;nbsp; Note that SQL Server only generates the warning for actual insert statements.&amp;nbsp; Update statements that try to create a duplicate key still fail with an error.&lt;/P&gt;
&lt;P&gt;Let's begin with a trivial insert into a unique clustered index:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;CREATE TABLE T_SRC (A INT, B INT)&lt;/P&gt;
&lt;P&gt;CREATE TABLE T_DST (A INT, B INT)&lt;BR&gt;CREATE UNIQUE CLUSTERED INDEX T_DST_A ON T_DST(A) &lt;B&gt;WITH IGNORE_DUP_KEY&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;INSERT T_DST SELECT * FROM T_SRC&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This insert yields the following rather mundane query plan:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; |--Clustered Index Insert(OBJECT:([T_DST].[T_DST_A]), SET:([T_DST].[A] = [T_SRC].[A],[T_DST].[B] = [T_SRC].[B]))&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |--Top(ROWCOUNT est 0)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |--Table Scan(OBJECT:([T_SRC]))&lt;/P&gt;
&lt;P&gt;If you were expecting something more exciting, I'm sorry for the disappointment.&amp;nbsp; So what's going on here?&amp;nbsp; SQL Server simply tries to insert each row.&amp;nbsp; If any insertion fails due to a duplicate key, SQL Server just converts the error into a warning, discards the failed row, and continues.&amp;nbsp; Since we only have the one clustered index and no non-clustered indexes to maintain, SQL Server either inserts or does &lt;EM&gt;not &lt;/EM&gt;insert each row into the single clustered index.&amp;nbsp; Either way, the integrity of the table is preserved.&lt;/P&gt;
&lt;P&gt;Now let's create a non-clustered index and see what happens:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;CREATE UNIQUE INDEX T_DST_B ON T_DST(B)&lt;/P&gt;
&lt;P&gt;INSERT T_DST SELECT * FROM T_SRC&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;As it turns out, aside from adding the extra index to the clustered index insert, nothing changes:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; |--Clustered Index Insert(OBJECT:([T_DST].[T_DST_A]), &lt;B&gt;OBJECT:([T_DST].[T_DST_B])&lt;/B&gt;, SET:([T_DST].[A] = [T_SRC].[A],[T_DST].[B] = [T_SRC].[B]))&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |--Top(ROWCOUNT est 0)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |--Table Scan(OBJECT:([T_SRC]))&lt;/P&gt;
&lt;P&gt;Even with two indexes (one clustered and one non-clustered) to maintain, SQL Server continues to use the same strategy of inserting rows and waiting to see whether any of the inserts fail due to duplicate keys.&amp;nbsp; This strategy works because SQL Server always maintains the clustered index first.&amp;nbsp; If it successfully inserts the row into the clustered index, it can safely proceed to insert the row into the non-clustered index.&amp;nbsp; If it cannot insert the row into the clustered index, it can discard the row without any risk of corrupting the indexes.&amp;nbsp; Once again, either way, the integrity of the table is preserved.&lt;/P&gt;
&lt;P&gt;It turns out that this strategy works perfectly so long as only the clustered index was created with the WITH IGNORE_DUP_KEY clause.&amp;nbsp; However, if we have even one non-clustered index that was created with the WITH IGNORE_DUP_KEY clause, this strategy no longer works.&amp;nbsp; Imagine what would happen if SQL Server were to insert a row into the clustered index only to encounter a duplicate key violation when trying to insert the same row into the non-clustered index.&amp;nbsp; At this point, SQL Server could not simply issue a warning and discard the row as this would leave the clustered and non-clustered indexes inconsistent.&amp;nbsp; Let's create a non-clustered index with the WITH IGNORE_DUP_KEY clause and see how SQL Server handles this case:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;DROP INDEX T_DST.T_DST_B&lt;BR&gt;CREATE UNIQUE INDEX T_DST_B ON T_DST(B) &lt;B&gt;WITH IGNORE_DUP_KEY&lt;/B&gt;&lt;B&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;INSERT T_DST SELECT * FROM T_SRC&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Finally, an interesting query plan:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; |--Clustered Index Insert(OBJECT:([T_DST].[T_DST_A]), OBJECT:([T_DST].[T_DST_B]), SET:([T_DST].[A] = [T_SRC].[A],[T_DST].[B] = [T_SRC].[B]))&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |--Top(TOP EXPRESSION:((1)))&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |--Segment&lt;BR&gt;&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; |--Sort(ORDER BY:([T_SRC].[B] ASC))&lt;BR&gt;&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;&amp;nbsp;&amp;nbsp; |--Assert(WHERE:(CASE WHEN [Expr1012] IS NOT NULL THEN (0) ELSE NULL END))&lt;BR&gt;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |--Nested Loops(Left Semi Join, OUTER REFERENCES:([T_SRC].[B]), DEFINE:([Expr1012] = [PROBE VALUE]))&lt;BR&gt;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |--Top(ROWCOUNT est 0)&lt;BR&gt;&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;&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; |--Table Scan(OBJECT:([T_SRC]))&lt;BR&gt;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |--Index Seek(OBJECT:([T_DST].[T_DST_B]), SEEK:([T_DST].[B]=[T_SRC].[B]) ORDERED FORWARD)&lt;/P&gt;
&lt;P&gt;There are two parts of this plan that handle duplicate keys.&amp;nbsp; The first part includes the left semi-join, index seek, and assert operators.&amp;nbsp; The second part includes the sort, segment, and top operators.&lt;/P&gt;
&lt;P&gt;For each row that we intend to insert, the left semi-join, index seek, and assert operators determine whether a matching row with the same key already exists in the non-clustered index. &amp;nbsp;If they&amp;nbsp;find a matching row, they issue the duplicate key warning, discard the row, and continue.&amp;nbsp; Let's explore exactly how these operators accomplish this task.&amp;nbsp; First, the table scan returns a row to insert.&amp;nbsp; The semi-join uses the index seek on the non-clustered index to determine whether a row with the same key already exists in the index.&amp;nbsp; Recall that a &lt;A title="Introduction to Joins" href="http://blogs.msdn.com/craigfr/archive/2006/07/19/671712.aspx"&gt;left semi-join&lt;/A&gt; ordinarily returns rows from the left (or first) input that join with at least one row from the right (or second) input.&amp;nbsp; This semi-join is special.&amp;nbsp; It returns all rows, whether or not they join, and outputs a PROBE column that indicates whether or not each row in fact joined.&amp;nbsp; (For two other examples of a semi-join with a probe column, see my subquery posts &lt;A title="Subqueries in CASE Expressions" href="http://blogs.msdn.com/craigfr/archive/2006/08/23/715306.aspx"&gt;here&lt;/A&gt; and &lt;A title="Subqueries: ANDs and ORs" href="http://blogs.msdn.com/craigfr/archive/2006/08/30/732409.aspx"&gt;here&lt;/A&gt;.)&amp;nbsp; Finally, the assert operator checks the value of the PROBE column.&amp;nbsp; If the index seek does &lt;I&gt;not&lt;/I&gt; return a matching row, the new row is not a duplicate and the assert operator returns it normally.&amp;nbsp; If the index seek does return a matching row, the assert operator issues the warning and discards the row.&lt;/P&gt;
&lt;P&gt;The sort, segment, and top operators check for duplicates in the stream of input rows.&amp;nbsp; If they find a duplicate input row, they issue the duplicate key warning, discard the duplicate row, and continue.&amp;nbsp; Again, let's explore exactly how these operators execute this task.&amp;nbsp; The sort simply ensures that any duplicate input rows are clustered one after the other in the input stream.&amp;nbsp; The segment operator compares adjacent rows checking for duplicates.&amp;nbsp; It performs two functions in this plan.&amp;nbsp; First, if it finds a duplicate row, it issues the warning.&amp;nbsp; Second, it "flags" groups of duplicate rows.&amp;nbsp; Unlike the assert operator, the segment operator does not discard any rows.&amp;nbsp; Instead, the top operator discards the duplicates.&amp;nbsp; The top operator in this plan is a special type of top known as a segment top.&amp;nbsp;&amp;nbsp; A normal top returns the first N rows and then stops.&amp;nbsp; A segment top returns the first N rows from each group of duplicate rows flagged by the segment operator.&amp;nbsp; In this case, the segment top returns only the first row from each group and, thus, eliminates the duplicates.&lt;/P&gt;
&lt;P&gt;Any rows that are not discarded by the time they reach the insert operator must be unique and can safely be inserted without triggering a uniqueness violation.&lt;/P&gt;
&lt;P&gt;If we create multiple non-clustered indexes with the WITH IGNORE_DUP_KEY clause, one set of these extra operators is inserted for each non-clustered index.&amp;nbsp; Note also that the plan needs these additional operators only for the non-clustered index.&amp;nbsp; The clustered index is handled as described at the beginning of this post.&lt;/P&gt;
&lt;P&gt;Finally, I want to comment briefly on the performance implications of the WITH IGNORE_DUP_KEY clause.&amp;nbsp;&amp;nbsp;On a clustered index, there is no plan change and the performance implications are negligible.&amp;nbsp; Unfortunately, on a non-clustered index, all of the additional operators discussed above are costly and do result in a measurable performance reduction.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=7334315" width="1" height="1"&gt;&lt;img alt="via softlogger.com" src="http://softlogger.com/postview.aspx?ArticleID=18625"&gt;</description><author>Craig Freedmans WebLog : Aggregation                                                                </author><pubDate>2008-01-30T00:00:00</pubDate><category>Database,SQL</category></item><item><title>ASP.NET MVC Example Application over Northwind with the Entity Framework</title><link>http://softlogger.com/18647/DatabaseSQL/asp-net-mvc-example-application-over-northwind-with-the-entity-framework.aspx</link><description>&lt;p&gt;Over last month over the holidays, Lance Olson and I spent some time porting &lt;a href="http://weblogs.asp.net/scottgu/archive/tags/MVC/default.aspx"&gt;ScottGu's excellent MVC example&lt;/a&gt; over the &lt;a href="http://msdn2.microsoft.com/en-us/library/aa697427(vs.80).aspx"&gt;Entity Framework&lt;/a&gt;.&amp;nbsp; I thought I'd share the results here and get your thoughts\feedback.&lt;/p&gt; &lt;p&gt;For this example, you will need:&lt;/p&gt; &lt;ul&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="http://msdn2.microsoft.com/en-gb/vstudio/default.aspx"&gt;VS2008&lt;/a&gt; (Free &lt;a href="http://msdn2.microsoft.com/en-us/vstudio/products/aa700831.aspx"&gt;trial&lt;/a&gt; ) &lt;/li&gt; &lt;li&gt;&lt;a href="http://asp.net/downloads/3.5-extensions/"&gt;ASP.NET 3.5 Extensions&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=D8AE4404-8E05-41FC-94C8-C73D9E238F82&amp;amp;displaylang=en"&gt;ADO.NET Entity Framework Tools Dec 07 Preview&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=06616212-0356-46A0-8DA2-EEBC53A68034&amp;amp;displaylang=en"&gt;Northwind sample database&lt;/a&gt; (just &lt;a href="http://brad_abrams.members.winisp.net/Projects/MVC+EFJan08/Northwind/NORTHWND.zip"&gt;northwnd.mdf&lt;/a&gt;)&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt; &lt;p&gt;&lt;strong&gt;&lt;u&gt;&lt;/u&gt;&lt;/strong&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;If you are the type that likes to eat your desert first, you can skip to the end and just &lt;a href="http://brad_abrams.members.winisp.net/Projects/MVC+EFJan08/Northwind%20MVC%20Example.zip"&gt;download the full working solution&lt;/a&gt;.&amp;nbsp; &lt;/p&gt; &lt;p&gt;&lt;strong&gt;&lt;u&gt;&lt;/u&gt;&lt;/strong&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;&lt;u&gt;Getting Started&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;File/New Project - Select ASP.NET MVC Web Application and Test&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/brada/WindowsLiveWriter/ASP.NETMVCExampleApplicationoverNorthwin_BA7B/image_2.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="165" alt="image" src="http://blogs.msdn.com/blogfiles/brada/WindowsLiveWriter/ASP.NETMVCExampleApplicationoverNorthwin_BA7B/image_thumb.png" width="244" border="0"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;This creates a single solution with both a web application project as well as a project we can use for unit testing.&amp;nbsp;&amp;nbsp; Both are pre-populated with the basic stuff you need to get going.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;&lt;u&gt;Creating the Routes&lt;/u&gt;&lt;/strong&gt; &lt;/p&gt; &lt;p&gt;One of the powerful new features that ASP.NET MVC brings to the table is the ability to customize the URLs that access your application. The URL routing feature explicitly breaks the connection between physical files on disk and the URL that is used to access a given bit of functionality.&amp;nbsp;&amp;nbsp; This is important for Search Engine Optimization as well as general usability of the website.&amp;nbsp;&amp;nbsp;&amp;nbsp; For example, rather than access &lt;a href="http://localhost/Products/ItemDetails.aspx?item=42"&gt;http://localhost/Products/ItemDetails.aspx?item=42&lt;/a&gt; you can now very give a pretty URL such as &lt;a href="http://localhost/Products/CodFishOil"&gt;http://localhost/Products/CodFishOil&lt;/a&gt;&amp;nbsp; &lt;/p&gt; &lt;p&gt;This is done by creating a route table in the global.asax file in the MVC Application.&amp;nbsp;&amp;nbsp; Luckily for us, the defaults included in the template work perfectly this application.&amp;nbsp; &lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: #2b91af"&gt;RouteTable&lt;/span&gt;.Routes.Add(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Route
&lt;/span&gt;{
    Url = &lt;span style="color: #a31515"&gt;"[controller]/[action]/[id]"&lt;/span&gt;,
    Defaults = &lt;span style="color: blue"&gt;new &lt;/span&gt;{ action = &lt;span style="color: #a31515"&gt;"Index"&lt;/span&gt;, id = (&lt;span style="color: blue"&gt;string&lt;/span&gt;)&lt;span style="color: blue"&gt;null &lt;/span&gt;},
    RouteHandler = &lt;span style="color: blue"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;MvcRouteHandler&lt;/span&gt;)
});
&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;This code spells out the format of the URLs we want to use for our site.&amp;nbsp; In particular, a URL of the format&lt;/p&gt;
&lt;p&gt;&lt;a href="http://localhost/Products/Details/CodFishOil"&gt;http://localhost/Products/Details/CodFishOil&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;would translate to the ProductsController class (notice we add the "Controller" suffix to the class name to make these classes stand out in the object model at design time).&amp;nbsp; Then the Action is a method on that class called Details and finally the argument to that details method is CodFishOil.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;It is of course possible to have other formats, simply by changing he regular expression in the URL pattern string.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;u&gt;Creating the Model&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The model represents the data you are going to use in the application.&amp;nbsp;&amp;nbsp; In our case, this is a pretty good place to start the core of the application.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;In the App_Data direction of the MVCApplication copy the Northwind.mdf file.&amp;nbsp; Northwind is likely the most common example database we have for SqlServer... You can download it from &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=06616212-0356-46A0-8DA2-EEBC53A68034&amp;amp;displaylang=en"&gt;the official location&lt;/a&gt;, or for just the raw file, feel &lt;a href="http://brad_abrams.members.winisp.net/Projects/MVC+EFJan08/Northwind/NORTHWND.zip"&gt;free to grab it from here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/brada/WindowsLiveWriter/ASP.NETMVCExampleApplicationoverNorthwin_BA7B/image_4.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="244" alt="image" src="http://blogs.msdn.com/blogfiles/brada/WindowsLiveWriter/ASP.NETMVCExampleApplicationoverNorthwin_BA7B/image_thumb_1.png" width="173" border="0"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Next, we need to create a LINQ model on top of northwind to make it easier to work with... You can do this with &lt;a href="http://www.hibernate.org/343.html"&gt;NHibernate&lt;/a&gt;, &lt;a href="http://msdn2.microsoft.com/en-us/library/bb425822.aspx"&gt;LinqToSql&lt;/a&gt;, &lt;a href="http://msdn2.microsoft.com/en-us/library/aa697427(vs.80).aspx"&gt;Entity Framework&lt;/a&gt; , or any other .NET &lt;a href="http://en.wikipedia.org/wiki/Object-relational_mapping"&gt;OR-Mapping&lt;/a&gt; technology.&amp;nbsp; As long as it results in .NET Object, the ASP.NET MVC framework can work with it.&amp;nbsp; In this case I am going to use the Entity Framework.&lt;/p&gt;
&lt;p&gt;Right click on the &lt;strong&gt;Models &lt;/strong&gt;directory and select add new item&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/brada/WindowsLiveWriter/ASP.NETMVCExampleApplicationoverNorthwin_BA7B/image_6.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="194" alt="image" src="http://blogs.msdn.com/blogfiles/brada/WindowsLiveWriter/ASP.NETMVCExampleApplicationoverNorthwin_BA7B/image_thumb_2.png" width="321" border="0"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;In the dialog select ADO.NET Entity Data Model.&lt;/p&gt;
&lt;p&gt;In the wizard, select "Generate from Database" and then go with the default "Northwnd" connection string.&lt;/p&gt;
&lt;p&gt;For our demo, we are only going to use the Categories, Products and Suppliers tables, but you could of course extend this demo to include a richer feature set.&amp;nbsp; But for now, unselect the Views and Stored Procedures and all the tables except those three..&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/brada/WindowsLiveWriter/ASP.NETMVCExampleApplicationoverNorthwin_BA7B/image_8.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="227" alt="image" src="http://blogs.msdn.com/blogfiles/brada/WindowsLiveWriter/ASP.NETMVCExampleApplicationoverNorthwin_BA7B/image_thumb_3.png" width="244" border="0"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;When you click finished, VS will create a set of .NET classes that are custom built for accessing this database and we get a nice designer for visualizing the data relationships.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/brada/WindowsLiveWriter/ASP.NETMVCExampleApplicationoverNorthwin_BA7B/image_10.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="152" alt="image" src="http://blogs.msdn.com/blogfiles/brada/WindowsLiveWriter/ASP.NETMVCExampleApplicationoverNorthwin_BA7B/image_thumb_4.png" width="244" border="0"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Notice, that the default names given to these classes still use the plural names from the database, but in our OR-Mapping they represent single instances, so to make the code easier to read, go in and change all the table names to their appropriate singular form: Category, Product and Supplier.&amp;nbsp;&amp;nbsp; Then Navigation properties on Product needs to be singular as there is only one Category and Suppler for each product.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/brada/WindowsLiveWriter/ASP.NETMVCExampleApplicationoverNorthwin_BA7B/image_28.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="146" alt="image" src="http://blogs.msdn.com/blogfiles/brada/WindowsLiveWriter/ASP.NETMVCExampleApplicationoverNorthwin_BA7B/image_thumb_13.png" width="244" border="0"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Next we need to cleanup the namespace so things look pretty in our code... Right click on the design surface then set the properties such that namespace is "NorthwindModels" and the Entity Container name to "NorthWindEntities" &lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/brada/WindowsLiveWriter/ASP.NETMVCExampleApplicationoverNorthwin_BA7B/image_18.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="200" alt="image" src="http://blogs.msdn.com/blogfiles/brada/WindowsLiveWriter/ASP.NETMVCExampleApplicationoverNorthwin_BA7B/image_thumb_8.png" width="244" border="0"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;While we are not 100% done with the model, we have gotten the lion's share of it complete.. Let's switch over and look at the controller.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;u&gt;Creating the Controller&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Right click on the Controller directory and select "Add new Item".&amp;nbsp; In the dialog find MVC Controller and be sure to give it a name that ends in the Controller suffix.&amp;nbsp; In our case we are writing the ProductsController.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/brada/WindowsLiveWriter/ASP.NETMVCExampleApplicationoverNorthwin_BA7B/image_14.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="148" alt="image" src="http://blogs.msdn.com/blogfiles/brada/WindowsLiveWriter/ASP.NETMVCExampleApplicationoverNorthwin_BA7B/image_thumb_6.png" width="244" border="0"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;OK, we are ready to start working in&amp;nbsp; ProductsController.cs&lt;/p&gt;
&lt;p&gt;The goal of the controller is to prepare the model for the view.&amp;nbsp;&amp;nbsp;&amp;nbsp; We want to bring as much logical as possible out of the view because it is so hard to test in the view.&amp;nbsp; So in the controller, we are going to be accessing the Model and getting it all set up so all the view has to do is spit out some data.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;The first thing we need, is access to our database.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;1. Add the right namespaces... Linq and a reference to our OR mapping.&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;using &lt;/span&gt;System.Linq;
&lt;span style="color: blue"&gt;using &lt;/span&gt;NorthwindModel;&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;2. Next, we create an instance of the NorthwindEntities container class.&amp;nbsp; Nearly all of our actions will access this class.&lt;/p&gt;&lt;pre class="code"&gt;    &lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ProductsController &lt;/span&gt;: &lt;span style="color: #2b91af"&gt;Controller
    &lt;/span&gt;{
        &lt;span style="color: #2b91af"&gt;NorthwindEntities &lt;/span&gt;Northwind = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;NorthwindEntities&lt;/span&gt;(); 
&lt;/pre&gt;
&lt;p&gt;&lt;/p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;OK, now we are ready to create our first action.. Listing all the categories.&amp;nbsp; Remember the job of the controller is to prepare the model for the view..&amp;nbsp;&amp;nbsp; When defining a new action, I like to start off by putting a comment that reminds me what the URL is that access this functionality.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;The next thing we do is access the Categories table from the model.&amp;nbsp; I snap the results to a generic collection class (you may have to add a reference to System.Collections.Generic) then we pass the results to the view named "Categories".&amp;nbsp;&amp;nbsp;&amp;nbsp; This is a very simple example, later we will see more complex logic here.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;&lt;span style="color: green"&gt;//URL: http://localhost/Products/Categories&lt;br&gt;&lt;/span&gt;[&lt;span style="color: #2b91af"&gt;ControllerAction&lt;/span&gt;]&lt;br&gt;&lt;span style="color: blue"&gt;public void &lt;/span&gt;Categories()&lt;br&gt;{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; List&amp;lt;&lt;span style="color: #2b91af"&gt;Category&lt;/span&gt;&amp;gt; categories = Northwind.Categories.ToList();&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; RenderView(&lt;span style="color: #a31515"&gt;"Categories"&lt;/span&gt;, categories);&lt;br&gt;}&lt;br&gt;&lt;/p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;Next step, we need to create the "Categories" view.. &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;u&gt;Creating the View&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Right click on the Views folder, add new Directory "Products".&amp;nbsp; This so we can organize all our views cleanly.&amp;nbsp; The Right click on Views/Products folder and add new item MVC View Content Page.&amp;nbsp; We are going to leverage the Master Page that comes with the default project to make this look a little more pretty.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/brada/WindowsLiveWriter/ASP.NETMVCExampleApplicationoverNorthwin_BA7B/image_20.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="163" alt="image" src="http://blogs.msdn.com/blogfiles/brada/WindowsLiveWriter/ASP.NETMVCExampleApplicationoverNorthwin_BA7B/image_thumb_9.png" width="244" border="0"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Call it Categories.aspx... It is important that the view name matches the first argument to the RenderView method above.&lt;/p&gt;
&lt;p&gt;The default project puts the master page in Views/Shared/Site.Master&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/brada/WindowsLiveWriter/ASP.NETMVCExampleApplicationoverNorthwin_BA7B/image_22.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="150" alt="image" src="http://blogs.msdn.com/blogfiles/brada/WindowsLiveWriter/ASP.NETMVCExampleApplicationoverNorthwin_BA7B/image_thumb_10.png" width="244" border="0"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;In order to get the strongly typed access to the ViewData we are passing in from the controller, we need to tell the View Page, the type to expect.&amp;nbsp; This is done by opening up the codebehind (Categories.aspx.cs) and changing the derived type from:&lt;/p&gt;&lt;pre class="code"&gt;    &lt;span style="color: blue"&gt;public partial class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Categories &lt;/span&gt;: &lt;span style="color: #2b91af"&gt;ViewPage&lt;/span&gt;
    {
    }
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;to:&lt;/pre&gt;
&lt;blockquote&gt;&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public partial class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Categories &lt;/span&gt;: &lt;span style="color: #2b91af"&gt;ViewPage&lt;/span&gt;&amp;lt; &lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Category&lt;/span&gt;&amp;gt; &amp;gt; 
{
}
&lt;/pre&gt;&lt;/blockquote&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;Then you simply write clean, simple, designable HTML.&amp;nbsp; Notice here I am looping over all the items returned in ViewData and pushing them out as a link.&amp;nbsp; I use the MVC helper method Html.ActionLink to create the URL for the List action with the appropriate product ID.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;pre class="code"&gt;    &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;h2&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;Browse Products&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;h2&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;

    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ul &lt;/span&gt;&lt;span style="color: red"&gt;class&lt;/span&gt;&lt;span style="color: blue"&gt;="categorylisting"&amp;gt;
    
      &lt;/span&gt;&lt;span style="background: #ffee62"&gt;&amp;lt;%&lt;/span&gt; &lt;span style="color: blue"&gt;foreach &lt;/span&gt;(&lt;span style="color: blue"&gt;var &lt;/span&gt;category &lt;span style="color: blue"&gt;in &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ViewData&lt;/span&gt;) { &lt;span style="background: #ffee62"&gt;%&amp;gt;
&lt;/span&gt;    
        &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;li&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
            &lt;/span&gt;&lt;span style="background: #ffee62"&gt;&amp;lt;%&lt;/span&gt;&lt;span style="color: blue"&gt;= &lt;/span&gt;Html.ActionLink(category.CategoryName, &lt;span style="color: blue"&gt;new &lt;/span&gt;{ action=&lt;span style="color: #a31515"&gt;"List"&lt;/span&gt;, id=category.CategoryName }) &lt;span style="background: #ffee62"&gt;%&amp;gt;&lt;/span&gt;            
        &lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;li&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    
      &lt;/span&gt;&lt;span style="background: #ffee62"&gt;&amp;lt;%&lt;/span&gt; } &lt;span style="background: #ffee62"&gt;%&amp;gt;
&lt;/span&gt;        
    &lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;ul&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;OK, we are finally ready to run it!&amp;nbsp; &lt;/p&gt;
&lt;p&gt;Hit F5, and navigate to the controller action we just wrote on &lt;a title="http://localhost:64701/products/Categories" href="http://localhost:64701/products/Categories"&gt;http://localhost:64701/products/Categories&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/brada/WindowsLiveWriter/ASP.NETMVCExampleApplicationoverNorthwin_BA7B/image_24.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="210" alt="image" src="http://blogs.msdn.com/blogfiles/brada/WindowsLiveWriter/ASP.NETMVCExampleApplicationoverNorthwin_BA7B/image_thumb_11.png" width="244" border="0"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Clicking on any of the links give you an error, because we haven't written the List action yet.. we will do that next.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;As an aside, if like me, you are in the habit of using "View in Browser" on aspx pages you develop, you are likely to see this error.&amp;nbsp; To reproduce, right click on Categories.aspx and select View in browser.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/brada/WindowsLiveWriter/ASP.NETMVCExampleApplicationoverNorthwin_BA7B/image_26.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="138" alt="image" src="http://blogs.msdn.com/blogfiles/brada/WindowsLiveWriter/ASP.NETMVCExampleApplicationoverNorthwin_BA7B/image_thumb_12.png" width="244" border="0"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;You get an error. Why?&amp;nbsp; Well, remember with the MVC model, all execution goes through the controller, the views themselves are not runnable.&amp;nbsp;&amp;nbsp; Future tooling will make this better, but in the mean time, use F5 or you can "run in browser" with default.aspx.. just be sure you have built the solution first!&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;u&gt;The List Action, View &lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;OK, let's now go back and add the List action that we are missing.&amp;nbsp; What we need to do here is find all the products with a give Category.&amp;nbsp;&amp;nbsp; First I need to get all the products out of the model, then I need to ensure that the Category references are loaded.&amp;nbsp; The entity framework offers an explicit loading model by default.&amp;nbsp; As such you have to explicitly load any tables you need.&amp;nbsp; And finally we render the view.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;pre class="code"&gt;&lt;span style="color: green"&gt;//example URL:http://localhost:64701/products/List/Confections
&lt;/span&gt;[&lt;span style="color: #2b91af"&gt;ControllerAction&lt;/span&gt;]
&lt;span style="color: blue"&gt;public void &lt;/span&gt;List(&lt;span style="color: blue"&gt;string &lt;/span&gt;id)
{
    &lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Product&lt;/span&gt;&amp;gt; products = Northwind.GetProductsByCategory(id);

    &lt;span style="color: green"&gt;//prepare the view by explicitly loading the categories  
    &lt;/span&gt;products.FindAll(p =&amp;gt; p.Category == &lt;span style="color: blue"&gt;null&lt;/span&gt;).ForEach(p =&amp;gt; p.CategoryReference.Load());

    RenderView(&lt;span style="color: #a31515"&gt;"ListingByCategory"&lt;/span&gt;, products);

}
&lt;/pre&gt;
&lt;p&gt;Notice, i am calling a custom method on the NorthwindDataContext class... Personally I like the idea of keeping all the data access logic encapsulated in that class.&amp;nbsp; So to define this method, Right click on the Model, add new Item, select CodeFile and name it NorthwindDataContext.cs and give it the implementation.&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;using &lt;/span&gt;System;
&lt;span style="color: blue"&gt;using &lt;/span&gt;System.Collections.Generic;
&lt;span style="color: blue"&gt;using &lt;/span&gt;System.Linq;

&lt;span style="color: blue"&gt;namespace &lt;/span&gt;NorthwindModel
{
    &lt;span style="color: blue"&gt;public partial class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;NorthwindEntities
    &lt;/span&gt;{

    }
}&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Now you can easily add data access methods to this class... such as the GetProductsByCategory() method we use above.&amp;nbsp; &lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Product&lt;/span&gt;&amp;gt; GetProductsByCategory(&lt;span style="color: blue"&gt;string &lt;/span&gt;category)
{
    &lt;span style="color: blue"&gt;return &lt;/span&gt;Products.Where(p =&amp;gt; p.Category.CategoryName == category).ToList();
}
&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;Next, we need to add the ListingByCategory view... We follow the same steps from above to add a ListingByCategory.aspx page in the Views/Products/ directory.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;This time, we should make the ViewData be of type List&amp;lt;Products&amp;gt;&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public partial class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ListingByCategory &lt;/span&gt;: &lt;span style="color: #2b91af"&gt;ViewPage&lt;/span&gt;&amp;lt; &lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Product&lt;/span&gt;&amp;gt; &amp;gt; 
 {
 }&lt;/pre&gt;
&lt;p&gt;Next, to implement the view, we simply loop over the view data and spit it out in the right format.&lt;/p&gt;&lt;pre class="code"&gt;  
&lt;span style="background: #ffee62"&gt;&amp;lt;%&lt;/span&gt;&lt;span style="color: green"&gt;--Print out the catagory name--&lt;/span&gt;&lt;span style="background: #ffee62"&gt;%&amp;gt;&lt;/span&gt;  
  &lt;span style="background: #ffee62"&gt;&amp;lt;%&lt;/span&gt; &lt;span style="color: blue"&gt;foreach &lt;/span&gt;(&lt;span style="color: blue"&gt;var &lt;/span&gt;product &lt;span style="color: blue"&gt;in &lt;/span&gt;ViewData) { &lt;span style="background: #ffee62"&gt;%&amp;gt;
&lt;/span&gt;  &lt;span style="background: #ffee62"&gt;&amp;lt;%&lt;/span&gt; &lt;span style="color: blue"&gt;if &lt;/span&gt;(product.Category.CategoryName != &lt;span style="color: blue"&gt;null&lt;/span&gt;) {  &lt;span style="background: #ffee62"&gt;%&amp;gt;&lt;/span&gt; 
    &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;h2&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;  &lt;/span&gt;&lt;span style="background: #ffee62"&gt;&amp;lt;%&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;product.Category.CategoryName  &lt;span style="background: #ffee62"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;h2&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt; 
    &lt;/span&gt;&lt;span style="background: #ffee62"&gt;&amp;lt;%&lt;/span&gt; &lt;span style="color: blue"&gt;break&lt;/span&gt;; &lt;span style="background: #ffee62"&gt;%&amp;gt;
&lt;/span&gt; &lt;span style="background: #ffee62"&gt;&amp;lt;%&lt;/span&gt;} &lt;span style="color: green"&gt;//end if &lt;/span&gt;&lt;span style="background: #ffee62"&gt;%&amp;gt;
&lt;/span&gt; &lt;span style="background: #ffee62"&gt;&amp;lt;%&lt;/span&gt;}&lt;span style="color: green"&gt;//end foreach &lt;/span&gt;&lt;span style="background: #ffee62"&gt;%&amp;gt;
&lt;/span&gt;        
    &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ul &lt;/span&gt;&lt;span style="color: red"&gt;class&lt;/span&gt;&lt;span style="color: blue"&gt;="productlist"&amp;gt;
    
        &lt;/span&gt;&lt;span style="background: #ffee62"&gt;&amp;lt;%&lt;/span&gt; &lt;span style="color: blue"&gt;foreach &lt;/span&gt;(&lt;span style="color: blue"&gt;var &lt;/span&gt;product &lt;span style="color: blue"&gt;in &lt;/span&gt;ViewData) { &lt;span style="background: #ffee62"&gt;%&amp;gt;
&lt;/span&gt;        
            &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;li&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;img &lt;/span&gt;&lt;span style="color: red"&gt;src&lt;/span&gt;&lt;span style="color: blue"&gt;="/Content/Images/&lt;/span&gt;&lt;span style="background: #ffee62"&gt;&amp;lt;%&lt;/span&gt;=product.ProductID&lt;span style="background: #ffee62"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="color: blue"&gt;.jpg" &lt;/span&gt;&lt;span style="color: red"&gt;alt&lt;/span&gt;&lt;span style="color: blue"&gt;="&lt;/span&gt;&lt;span style="background: #ffee62"&gt;&amp;lt;%&lt;/span&gt;=product.ProductName &lt;span style="background: #ffee62"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="color: blue"&gt;" /&amp;gt; 
                &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;br&lt;/span&gt;&lt;span style="color: blue"&gt;/&amp;gt; 
                &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;a &lt;/span&gt;&lt;span style="color: red"&gt;href&lt;/span&gt;&lt;span style="color: blue"&gt;="/Products/Detail/&lt;/span&gt;&lt;span style="background: #ffee62"&gt;&amp;lt;%&lt;/span&gt;=product.ProductID &lt;span style="background: #ffee62"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="color: blue"&gt;"&amp;gt; &lt;/span&gt;&lt;span style="background: #ffee62"&gt;&amp;lt;%&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;product.ProductName &lt;span style="background: #ffee62"&gt;%&amp;gt;&lt;/span&gt; &lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;a&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;br &lt;/span&gt;&lt;span style="color: blue"&gt;/&amp;gt;
                &lt;/span&gt;Price: &lt;span style="background: #ffee62"&gt;&amp;lt;%&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&lt;span style="color: #2b91af"&gt;String&lt;/span&gt;.Format(&lt;span style="color: #a31515"&gt;"{0:C2}"&lt;/span&gt;, product.UnitPrice)&lt;span style="background: #ffee62"&gt;%&amp;gt;&lt;/span&gt; 
                  &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;span &lt;/span&gt;&lt;span style="color: red"&gt;class&lt;/span&gt;&lt;span style="color: blue"&gt;="editlink" "&amp;gt;
                    &lt;/span&gt;(&lt;span style="background: #ffee62"&gt;&amp;lt;%&lt;/span&gt;&lt;span style="color: blue"&gt;= &lt;/span&gt;Html.ActionLink(&lt;span style="color: #a31515"&gt;"Edit"&lt;/span&gt;, &lt;span style="color: blue"&gt;new &lt;/span&gt;{ Action=&lt;span style="color: #a31515"&gt;"Edit"&lt;/span&gt;, ID=product.ProductID })&lt;span style="background: #ffee62"&gt;%&amp;gt;&lt;/span&gt;)
                &lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;span&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
           
            &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;li&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    
        &lt;/span&gt;&lt;span style="background: #ffee62"&gt;&amp;lt;%&lt;/span&gt; } &lt;span style="background: #ffee62"&gt;%&amp;gt;
&lt;/span&gt;        
    &lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;ul&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;Once you add the /Content/Images directory from the sample project you get this:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/brada/WindowsLiveWriter/ASP.NETMVCExampleApplicationoverNorthwin_BA7B/image_30.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="244" alt="image" src="http://blogs.msdn.com/blogfiles/brada/WindowsLiveWriter/ASP.NETMVCExampleApplicationoverNorthwin_BA7B/image_thumb_14.png" width="214" border="0"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;u&gt;Unit Testing&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;One of the primary&amp;nbsp; reasons for using the MVC model is to enable Test Driven Development and more generically Unit Testing.&amp;nbsp; Unit testing UIs is notoriously difficult.&amp;nbsp; Automation is fragile and hiring an army of testers to click on buttons is not always cost effective.&amp;nbsp; The model MVC is going for is to separate out as much code (and therefore potential bugs) as possible into the Model and the Controller where they are testable. &lt;/p&gt;
&lt;p&gt;So, we are going to write Unit Tests for the two control methods we just created and the corresponding logic in the model.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;First, we need to setup our testing environment.&amp;nbsp; The default template already created a Test project we can start to customize.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;1. In the MvcApplicationTest project, create a new class called ProductControllerTest.cs&lt;/p&gt;
&lt;p&gt;2. Add a method for testing the Categories action we defined above.&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;namespace &lt;/span&gt;MvcApplicationTest.Controllers
{

    [&lt;span style="color: #2b91af"&gt;TestClass&lt;/span&gt;]
    &lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ProductsControllerTest
    &lt;/span&gt;{

        [&lt;span style="color: #2b91af"&gt;TestMethod&lt;/span&gt;]
        &lt;span style="color: blue"&gt;public void &lt;/span&gt;Categories()
        {

        }
    }
&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;3. We want to test the controller we wrote, but we don't want to load IIS and all of ASP.NET... we want to have the leanest, most simple system we can to avoid test breaks, etc.&amp;nbsp;&amp;nbsp; To that end, I created a test specific subclass of the ProductsController we defined above.&amp;nbsp; In this subclass I override the RenderView method.&amp;nbsp; Instead of calling out to ASP.NET, my test specific implement simply captures the arguments so they can be queried later in the test.&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TestProductsController &lt;/span&gt;: ProductsController
{
    &lt;span style="color: blue"&gt;public string &lt;/span&gt;ViewName { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }
    &lt;span style="color: blue"&gt;public string &lt;/span&gt;MasterName { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }
    &lt;span style="color: blue"&gt;public new object &lt;/span&gt;ViewData { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }
    &lt;span style="color: blue"&gt;protected override void &lt;/span&gt;RenderView(&lt;span style="color: blue"&gt;string &lt;/span&gt;viewName, &lt;span style="color: blue"&gt;string &lt;/span&gt;masterName, &lt;span style="color: blue"&gt;object &lt;/span&gt;viewData)
    {
        ViewData = viewData;
        MasterName = masterName;
        ViewName = viewName;
    }
  }&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;4. Now we implement the test!&amp;nbsp; First we create an instance of our test controller, then I create some dummy&amp;nbsp; (or mock) data.&amp;nbsp; The idea here is that we don't want to hit the production database (or any database for that mater) in our tests.&amp;nbsp; We want exactly the data we need for the test, no more, no less.&amp;nbsp; Then we set up the NorthwindDataContext to use our data rather than the data from the database.&amp;nbsp; Then we call the controller action we are trying to test.&amp;nbsp; Finally, we assert a few things..&amp;nbsp; that the type of the ViewData is right, that the number&amp;nbsp; of items returned is right, etc.&amp;nbsp;&amp;nbsp; Notice, you will need to add a reference to the EntityFramework (System.Data.Entity.dll) in your test project to use these EF generated types like Product, Category, etc.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;pre class="code"&gt;[&lt;span style="color: #2b91af"&gt;TestMethod&lt;/span&gt;]
&lt;span style="color: blue"&gt;public void &lt;/span&gt;Categories()
{
    &lt;span style="color: green"&gt;// Create Products Controller
    &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TestProductsController &lt;/span&gt;controller = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TestProductsController&lt;/span&gt;();

    &lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Category&lt;/span&gt;&amp;gt; l = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Category&lt;/span&gt;&amp;gt;();
    l.Add(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Category&lt;/span&gt;() { CategoryName = &lt;span style="color: #a31515"&gt;"Drink" &lt;/span&gt;});
    l.Add(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Category&lt;/span&gt;() { CategoryName = &lt;span style="color: #a31515"&gt;"Food" &lt;/span&gt;});
    l.Add(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Category&lt;/span&gt;() { CategoryName = &lt;span style="color: #a31515"&gt;"Cheese" &lt;/span&gt;});

    controller.Northwind.TheCategories = l.AsQueryable();

    &lt;span style="color: green"&gt;// Invoke Controller Action
    &lt;/span&gt;controller.Categories();

    &lt;span style="color: green"&gt;// Verify Detail Action Behavior
    &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.AreEqual(&lt;span style="color: blue"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Category&lt;/span&gt;&amp;gt;),
                     controller.ViewData.GetType(),
                     &lt;span style="color: #a31515"&gt;"Product object Passed to View"&lt;/span&gt;);

    &lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.AreEqual(3,
                     ((&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Category&lt;/span&gt;&amp;gt;)controller.ViewData).Count,
                     &lt;span style="color: #a31515"&gt;"Correct Number of Catagories returned"&lt;/span&gt;);

    &lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.AreEqual(&lt;span style="color: #a31515"&gt;"Food"&lt;/span&gt;,
                     ((&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Category&lt;/span&gt;&amp;gt;)controller.ViewData)[1].CategoryName,
                     &lt;span style="color: #a31515"&gt;"Correct Product Object Passed to View"&lt;/span&gt;);

    &lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.AreEqual(&lt;span style="color: #a31515"&gt;"Categories"&lt;/span&gt;,
                     controller.ViewName,
                     &lt;span style="color: #a31515"&gt;"Correct View Rendered"&lt;/span&gt;);

}
&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;5. Set the connection string in the test project so that it access the metadata from EF model, but &lt;strong&gt;&lt;em&gt;does not open the database&lt;/em&gt;&lt;/strong&gt;.&amp;nbsp; In MVCApplicationTest add an app.config file to the root of the project with the this connection string. &lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;?&lt;/span&gt;&lt;span style="color: #a31515"&gt;xml &lt;/span&gt;&lt;span style="color: red"&gt;version&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;1.0&lt;/span&gt;"&lt;span style="color: blue"&gt;?&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;configuration&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;connectionStrings&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;add &lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;NorthwindEntities&lt;/span&gt;"
         &lt;span style="color: red"&gt;connectionString&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;metadata=res://*/;provider=System.Data.SqlClient;&lt;/span&gt;"
         &lt;span style="color: red"&gt;providerName&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;System.Data.EntityClient&lt;/span&gt;" &lt;span style="color: blue"&gt;/&amp;gt;
  &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;connectionStrings&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;configuration&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Now, we need to go back to the EDM designer and set it to embed the metadata for the model as part of the assembly.&amp;nbsp; This makes our connection string above much more simple.&amp;nbsp; Double click on the edmx file, then click on the conceptual model in the model browser and in the property sheet you change the property Metadata Artifact Processing from “Copy to Output Directory” to “Embed in&amp;nbsp; Output Assembly”&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;a href="http://blogs.msdn.com/blogfiles/brada/WindowsLiveWriter/ASP.NETMVCExampleApplicationoverNorthwin_BA7B/image_33.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="168" alt="image" src="http://blogs.msdn.com/blogfiles/brada/WindowsLiveWriter/ASP.NETMVCExampleApplicationoverNorthwin_BA7B/image_thumb_5.png" width="244" border="0"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;6. Now we need to do just a bit of setup in the MVCApplication to enable a great testing experience... There are a few tricks here and what I am showing is NOT the definitive model (there isn't a definitive model yet)... but I like it, so what the heck!&lt;/p&gt;
&lt;p&gt;MVCApplication/Model/NorthwindDataContext.cs add the following encapsulation of the Categories property.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;private &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IQueryable&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Product&lt;/span&gt;&amp;gt; savedProducts = &lt;span style="color: blue"&gt;null&lt;/span&gt;;
&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IQueryable&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Product&lt;/span&gt;&amp;gt; TheProducts
{
    &lt;span style="color: blue"&gt;get
    &lt;/span&gt;{
        &lt;span style="color: blue"&gt;if &lt;/span&gt;(savedProducts == &lt;span style="color: blue"&gt;null&lt;/span&gt;) savedProducts = &lt;span style="color: blue"&gt;this&lt;/span&gt;.Products;
        &lt;span style="color: blue"&gt;return &lt;/span&gt;savedProducts;
    }
    &lt;span style="color: blue"&gt;set
    &lt;/span&gt;{
        savedProducts = &lt;span style="color: blue"&gt;value&lt;/span&gt;;
    }
}
&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;Then, make sure that all access go through this abstraction.&amp;nbsp; For example:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Product&lt;/span&gt;&amp;gt; GetProductsByCategory(&lt;span style="color: blue"&gt;string &lt;/span&gt;category)
{
    &lt;span style="color: blue"&gt;return &lt;/span&gt;TheProducts.Where(p =&amp;gt; p.Category.CategoryName == category).ToList();
}&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;Finally, we need to make sure the NorthwindEntities is accessible from the test classes, so in ProductsController.cs add the "public" modifier.&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;NorthwindEntities &lt;/span&gt;Northwind = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;NorthwindEntities&lt;/span&gt;();&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Now, we are able to run our test.&amp;nbsp; You can do this by setting the test project as being the "startup project" (right click on the test project) or you can select Test/Run menu option.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/brada/WindowsLiveWriter/ASP.NETMVCExampleApplicationoverNorthwin_BA7B/image_35.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="167" alt="image" src="http://blogs.msdn.com/blogfiles/brada/WindowsLiveWriter/ASP.NETMVCExampleApplicationoverNorthwin_BA7B/image_thumb_7.png" width="244" border="0"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Well, that is the lap around MVC+EF... There is a lot more to the sample I posted.&amp;nbsp; If there is interest and I get the time, I will walk through the rest in future blog posts, but all the source code is there, so you can have fun with it on your own!&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Enjoy!&lt;/p&gt;
&lt;p&gt;You can download the &lt;a href="http://brad_abrams.members.winisp.net/Projects/MVC+EFJan08/Northwind%20MVC%20Example.zip"&gt;full working example here&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=7274283" width="1" height="1"&gt;&lt;img alt="via softlogger.com" src="http://softlogger.com/postview.aspx?ArticleID=18647"&gt;</description><author>Brad Abrams</author><pubDate>2008-01-29T00:00:00</pubDate><category>Database,SQL</category></item><item><title>LINQ to SQL vs. LINQ to Entities Smackdown!</title><link>http://softlogger.com/18545/DatabaseSQL/linq-to-sql-vs-linq-to-entities-smackdown.aspx</link><description>&lt;P&gt;OK, maybe not a smackdown... but it sure sounded like a good title.&lt;/P&gt;
&lt;P&gt;There's a great &lt;A class=" " href="http://msdn2.microsoft.com/en-us/library/cc161164.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/cc161164.aspx"&gt;paper on MSDN that describes the similarities and differences in LINQ to SQL and LINQ to Entities&lt;/A&gt; from the Entity Framework.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;I have done a bunch of LINQ demos recently, a lot of people are really fired up about the simplicity that LINQ brings to the table.&amp;nbsp; What is confusing is how LINQ to SQL conflicts and overlaps with what LINQ to Entities offers.&amp;nbsp; From the article referenced above, the key takeaways are summarized below.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;LINQ to SQL is good when your solution is targeted classes are going to be targeted at SQL Server and you have a 1:1 relationship between the domain model and database schema.&lt;/P&gt;
&lt;P&gt;Use LINQ to Entities as an ORM solution where&amp;nbsp;your classes may be 1:1 with the database or may have a very different structure from the database schema and targets.&amp;nbsp; LINQ to Entities&amp;nbsp;will also good for 3rd party database solutions.&amp;nbsp; &lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=7314633" width="1" height="1"&gt;&lt;img alt="via softlogger.com" src="http://softlogger.com/postview.aspx?ArticleID=18545"&gt;</description><author>Kirk Allen Evans Blog</author><pubDate>2008-01-29T00:00:00</pubDate><category>Database,SQL</category></item><item><title>Importing a textfile to a typed dataset (failing and resolving)</title><link>http://softlogger.com/18653/