<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>{get; set;} : CODE!</title>
	<atom:link href="http://daveswersky.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://daveswersky.com</link>
	<description>Dave Swersky&#039;s {mis}Adventures in .NET Programming</description>
	<lastBuildDate>Fri, 16 Dec 2011 20:20:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='daveswersky.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/194cabc2fcba5c79c24715cf0d22aaa2?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>{get; set;} : CODE!</title>
		<link>http://daveswersky.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://daveswersky.com/osd.xml" title="{get; set;} : CODE!" />
	<atom:link rel='hub' href='http://daveswersky.com/?pushpress=hub'/>
		<item>
		<title>Development Burnout: A Cautionary Tale</title>
		<link>http://daveswersky.com/2011/07/15/development-burnout-a-cautionary-tale/</link>
		<comments>http://daveswersky.com/2011/07/15/development-burnout-a-cautionary-tale/#comments</comments>
		<pubDate>Fri, 15 Jul 2011 17:06:32 +0000</pubDate>
		<dc:creator>Dave Swersky</dc:creator>
				<category><![CDATA[LINQ]]></category>
		<category><![CDATA[Thoughts]]></category>
		<category><![CDATA[general work burnout]]></category>

		<guid isPermaLink="false">http://daveswersky.com/?p=614</guid>
		<description><![CDATA[Any who subscribe to my blog have noticed by now that there has been quite a long time since I made a new post.  I make no excuses  but I thought I&#8217;d share the reasons behind it in case they might prove useful to some. The simple fact is I accepted a side gig and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=daveswersky.com&amp;blog=9388197&amp;post=614&amp;subd=daveswersky&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Any who subscribe to my blog have noticed by now that there has been quite a long time since I made a new post.  <a href="http://www.hanselman.com/blog/BlogInteresting32WaysToKeepYourBlogFromSucking.aspx" target="_blank">I make no excuses</a>  but I thought I&#8217;d share the reasons behind it in case they might prove useful to some.</p>
<p>The simple fact is I accepted a side gig and totally burned myself out. Crispy-fried. I was working 60-80 hour weeks between my primary and secondary gigs. I still enjoy writing code and developing software (two related but different activities, believe it or not.) However, I did so much of it in such a short time that I&#8217;ve needed an extended break.</p>
<p>Moral of the story? No project or dollars are worth hiding from your family in your basement for months on end. If you attack something you love with such fervor, you will not love it any longer it by the time you&#8217;re finished. Balance is needed. Pace yourself. You have a lifetime to achieve your goals in your personal and professional life. Don&#8217;t allow one to overshadow the other- keep both chugging along at a reasonable pace, and you will see <em>most </em>of your dreams in each fulfilled.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/daveswersky.wordpress.com/614/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/daveswersky.wordpress.com/614/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/daveswersky.wordpress.com/614/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/daveswersky.wordpress.com/614/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/daveswersky.wordpress.com/614/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/daveswersky.wordpress.com/614/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/daveswersky.wordpress.com/614/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/daveswersky.wordpress.com/614/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/daveswersky.wordpress.com/614/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/daveswersky.wordpress.com/614/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/daveswersky.wordpress.com/614/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/daveswersky.wordpress.com/614/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/daveswersky.wordpress.com/614/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/daveswersky.wordpress.com/614/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=daveswersky.com&amp;blog=9388197&amp;post=614&amp;subd=daveswersky&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://daveswersky.com/2011/07/15/development-burnout-a-cautionary-tale/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0e9420fd2a6d39a3779e1d9119834bff?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">daveswersky</media:title>
		</media:content>
	</item>
		<item>
		<title>Automapper and Silverlight 4?  Yes Please!</title>
		<link>http://daveswersky.com/2011/01/16/automapper-and-silverlight-4-yes-please/</link>
		<comments>http://daveswersky.com/2011/01/16/automapper-and-silverlight-4-yes-please/#comments</comments>
		<pubDate>Sun, 16 Jan 2011 20:23:29 +0000</pubDate>
		<dc:creator>Dave Swersky</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[automapper]]></category>
		<category><![CDATA[silverlight4]]></category>

		<guid isPermaLink="false">http://daveswersky.com/?p=607</guid>
		<description><![CDATA[I&#8217;m working on a fairly complex Silverlight application (Entity Framework 4, Prism/Unity, WCF RIA Services) and suddenly ran head-first into a need for some object mapping.  I haven&#8217;t done this before, but I had heard of Automapper so I Googled it and read the documentation.  Perfect! Then I read up on the Silverlight Automapper release. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=daveswersky.com&amp;blog=9388197&amp;post=607&amp;subd=daveswersky&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m working on a fairly complex Silverlight application (Entity Framework 4, Prism/Unity, WCF RIA Services) and suddenly ran head-first into a need for some object mapping.  I haven&#8217;t done this before, but I had heard of <a href="http://automapper.codeplex.com/" target="_blank">Automapper</a> so I Googled it and read the documentation.  Perfect!</p>
<p>Then I read up on the <a href="http://automapper.codeplex.com/releases/view/40707" target="_blank">Silverlight Automapper release</a>.  Uh-oh&#8230; last built in February 2010.  For Silverlight 3.  Curses&#8230;</p>
<p>I had two options at this point.  Do my mapping at the server side using the &#8220;regular&#8221; Automapper, or dig in and make Automapper Silverlight Edition work for me.  I downloaded the source, thinking I could (as I had done before with other projects) simply change the compilation target to Silverlight 4 and recompile.  Tried this and BAM!  No worky.  The version of mscorlib is 2.0.</p>
<p>Tried removing mscorlib and re-adding it from the Reference Assemblies.  BAM!  <a href="http://connect.microsoft.com/VisualStudio/feedback/details/519214/silverlight-4-application-project-remove-reference-to-mscorlib-or-system-core-and-they-cant-be-readded" target="_blank">Visual Studio bug</a>.</p>
<p>OK, so this will have to be a new project:</p>
<ol>
<li>File-New Project/New Silverlight Application.  Call it Automapper.Silverlight4.</li>
<li>Copy the &#8220;lib&#8221; folder from the Automapper source into the root folder of your new build</li>
<li>Add Reference to Castle.Core and Castle.DynamicProxy2 from the lib folder (don&#8217;t worry about the net3.5 folder, still works)</li>
<li>Right-click the project and select Add Existing Item</li>
<li>Navigate to the Automapper source and select all files in the root, <strong>then select Add As Link from the dropdown.</strong></li>
<li>Create Internal and Mappers folders and repeat the above steps for those folders in the Automapper source project.</li>
<li>Delete links to DataReaderMapper and ListSourceMapper under Mappers folder (not supported by Silverlight.)</li>
<li>Build!</li>
</ol>
<p>It works!  I now have Automapper working in a Silverlight 4 application.  I&#8217;m sure I&#8217;m not the first to try this, but it&#8217;s good to know it&#8217;s possible.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/daveswersky.wordpress.com/607/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/daveswersky.wordpress.com/607/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/daveswersky.wordpress.com/607/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/daveswersky.wordpress.com/607/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/daveswersky.wordpress.com/607/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/daveswersky.wordpress.com/607/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/daveswersky.wordpress.com/607/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/daveswersky.wordpress.com/607/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/daveswersky.wordpress.com/607/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/daveswersky.wordpress.com/607/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/daveswersky.wordpress.com/607/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/daveswersky.wordpress.com/607/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/daveswersky.wordpress.com/607/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/daveswersky.wordpress.com/607/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=daveswersky.com&amp;blog=9388197&amp;post=607&amp;subd=daveswersky&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://daveswersky.com/2011/01/16/automapper-and-silverlight-4-yes-please/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0e9420fd2a6d39a3779e1d9119834bff?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">daveswersky</media:title>
		</media:content>
	</item>
		<item>
		<title>How did you get started in programming?</title>
		<link>http://daveswersky.com/2010/12/21/how-did-you-get-started-in-programming/</link>
		<comments>http://daveswersky.com/2010/12/21/how-did-you-get-started-in-programming/#comments</comments>
		<pubDate>Tue, 21 Dec 2010 15:48:57 +0000</pubDate>
		<dc:creator>Dave Swersky</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://daveswersky.com/?p=372</guid>
		<description><![CDATA[I found this meme floating around some time ago, and thought it would be fun! How old were you when you started programming? Technically, about eight years old.  If you count plotting my initials on an Apple II+ in low-res, point by point, then that&#8217;s my first program. How did you get started in programming? [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=daveswersky.com&amp;blog=9388197&amp;post=372&amp;subd=daveswersky&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I found this meme floating around some time ago, and thought it would be fun!</p>
<p><strong>How old were you when you started programming?<br />
</strong>Technically, about eight years old.  If you count plotting my initials on an Apple II+ in low-res, point by point, then that&#8217;s my first program.</p>
<p><strong> How did you get started in programming?<br />
</strong>My first real job programming was in the late 90&#8242;s.  I developed an event tracking system in Access for a single&#8217;s activity club.  They were a franchise until the franchiser packed up and disappeared, which left several franchisees around the country stuck with a bespoke Notes database.  The IT shop that developed the Notes system wanted more than the clubs could afford to support it.  I grabbed a book on Access and started coding.  A few months later, I had sold the system to five clubs.  I was hooked.</p>
<p><strong></strong><br />
<strong> What was your first language?<br />
</strong>Visual Basic was the first language I learned to any level of competence.  I&#8217;ve since moved on to C# and javascript.<strong><br />
</strong><br />
<strong> What was the first real program you wrote?<br />
</strong>The event and member tracking system was the first money-earning production program I wrote.<br />
<strong> </strong></p>
<p><strong>What languages have you used since you started programming?<br />
</strong>C# is my &#8220;daily driver&#8221; language.  I also know Visual Basic, VBScript, and javascript.  I have a passing familiarity with C++ and Actionscript.<strong><br />
</strong><br />
<strong> What was your first professional programming gig?<br />
</strong>My first non-moonlighting gig was a contract with Texas Instruments, writing legacy ASP applications in VBScript.  I didn&#8217;t like that job very much, but it did demonstrate to me that I could make a living programming.</p>
<p><strong> If you knew then what you know now, would you have started programming?<br />
</strong>Absolutely.  I&#8217;m lucky to have found something I enjoy doing so much that also earns me and my family a living.  I&#8217;d still be doing it even if I couldn&#8217;t make a dime.</p>
<p><strong>If there is one thing you learned along the way that you would tell new developers, what would it be?<br />
</strong>99% of the information you need to learn your craft is available online.  I had a few mentors, but once I <em>learned how to learn </em>about programming<em>,</em> I discovered that the best answers are the ones you find for yourself.   That doesn&#8217;t mean you shouldn&#8217;t look to others for guidance and advice, just don&#8217;t use other people as your first resource for answers.  Don&#8217;t be satisfied with &#8220;it works.&#8221;  Challenge your assumptions, keep looking for the best patterns, and learn from the experts wherever you can.</p>
<p><strong> What’s the most fun you’ve ever had … programming?<br />
</strong>Ah, my magnum opus.  In the early aughts (2001) I developed an asset management system for a managed hosting company in Texas.  They were cramming their server data (over 7,000 servers) into a CRM and needed something better.  They were working on a hugely complex system, but it wasn&#8217;t due for months.  I bought several HP Jornada handheld computers- clamshell things with a full keyboard and PC card slot.  All the servers were marked with barcodes.  We scanned the ID information and &#8220;U-Top&#8221; (the position of the servers in the racks) of all 7,000+ servers in a single weekend, using the handhelds and some barcode scanners.  The data was then synched to a SQL Server using SQL Server CE 1.0.<br />
Then, using legacy ASP and some amazing artwork created by a colleague, we built a rack visualizer.  I developed a web-based system that allowed users to view the datacenter in a top-down view, click a rack, and see the contents of any rack.  You could hover over a server and see its status, and over blank space to reserve  a spot for a new server.  This combined with a tracking system that allowed users to track the progress of a server from the build center to the data center and back, as well as movement of assets within the corporate office.  I learned a <em>lot </em>from this experience, and consider it my greatest overall achievement&#8230; so far <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/daveswersky.wordpress.com/372/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/daveswersky.wordpress.com/372/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/daveswersky.wordpress.com/372/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/daveswersky.wordpress.com/372/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/daveswersky.wordpress.com/372/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/daveswersky.wordpress.com/372/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/daveswersky.wordpress.com/372/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/daveswersky.wordpress.com/372/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/daveswersky.wordpress.com/372/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/daveswersky.wordpress.com/372/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/daveswersky.wordpress.com/372/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/daveswersky.wordpress.com/372/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/daveswersky.wordpress.com/372/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/daveswersky.wordpress.com/372/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=daveswersky.com&amp;blog=9388197&amp;post=372&amp;subd=daveswersky&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://daveswersky.com/2010/12/21/how-did-you-get-started-in-programming/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0e9420fd2a6d39a3779e1d9119834bff?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">daveswersky</media:title>
		</media:content>
	</item>
		<item>
		<title>Bizarre Errors When Using Telerik Controls</title>
		<link>http://daveswersky.com/2010/12/15/bizarre-errors-when-using-telerik-controls/</link>
		<comments>http://daveswersky.com/2010/12/15/bizarre-errors-when-using-telerik-controls/#comments</comments>
		<pubDate>Wed, 15 Dec 2010 21:43:50 +0000</pubDate>
		<dc:creator>Dave Swersky</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[silverlight telerik]]></category>

		<guid isPermaLink="false">http://daveswersky.com/?p=604</guid>
		<description><![CDATA[I&#8217;m in the process of developing a complete line-of-business application in Silverlight.  I have a Telerik Premium license and most of the controls I use are Telerik controls. At one point in my development process, I innocently added an &#8220;Up/Down&#8221; control to a UserControl, using Blend 4.  Suddenly and for no apparent reason, I could [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=daveswersky.com&amp;blog=9388197&amp;post=604&amp;subd=daveswersky&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m in the process of developing a complete line-of-business application in Silverlight.  I have a Telerik Premium license and most of the controls I use are Telerik controls.</p>
<p>At one point in my development process, I innocently added an &#8220;Up/Down&#8221; control to a UserControl, using Blend 4.  Suddenly and for no apparent reason, I could no longer see the UserControl in Visual Studio 2010.  I would get a very odd looking blank page.  I could still edit it in Blend, however, and I&#8217;m under a time crunch so I carried on.</p>
<p>Today, Blend started crashing when trying to open the UserControl.  I now had no design surface and I&#8217;m struggling with other issues.  Among other strange issues, this error appeared in the VS designer:</p>
<p><em>An unhandled exception was encountered while trying to render the current silverlight project on the design surface. To diagnose this failure, please try to run the project in a regular browser using the silverlight developer runtime.</em></p>
<p>If I reloaded the designer I would go back to the blank page.  After much gnashing of teeth, I tried copying this control to another project in my solution.   After commenting out a few lines, Voila!  Design surface!</p>
<p><strong>The Solution: </strong>When I used Blend to add the &#8220;up/down&#8221; control, it added a reference to a <em>prior version </em>of the Telerik.Windows.Controls.Input assembly to my project.  I had several other Telerik assemblies referenced, all Q3 2010 version.  The mismatched versions played hell with the designer and I was stuck.  I removed the offending prior versions and replaced them with the correct ones, and life was good.  Hope this saves you some time and gray hairs.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/daveswersky.wordpress.com/604/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/daveswersky.wordpress.com/604/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/daveswersky.wordpress.com/604/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/daveswersky.wordpress.com/604/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/daveswersky.wordpress.com/604/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/daveswersky.wordpress.com/604/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/daveswersky.wordpress.com/604/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/daveswersky.wordpress.com/604/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/daveswersky.wordpress.com/604/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/daveswersky.wordpress.com/604/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/daveswersky.wordpress.com/604/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/daveswersky.wordpress.com/604/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/daveswersky.wordpress.com/604/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/daveswersky.wordpress.com/604/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=daveswersky.com&amp;blog=9388197&amp;post=604&amp;subd=daveswersky&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://daveswersky.com/2010/12/15/bizarre-errors-when-using-telerik-controls/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0e9420fd2a6d39a3779e1d9119834bff?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">daveswersky</media:title>
		</media:content>
	</item>
		<item>
		<title>My Journey with the StackExchange API</title>
		<link>http://daveswersky.com/2010/08/02/my-journey-with-the-stackexchange-api/</link>
		<comments>http://daveswersky.com/2010/08/02/my-journey-with-the-stackexchange-api/#comments</comments>
		<pubDate>Mon, 02 Aug 2010 15:29:24 +0000</pubDate>
		<dc:creator>Dave Swersky</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[stackexchange]]></category>
		<category><![CDATA[wpf]]></category>

		<guid isPermaLink="false">http://daveswersky.com/?p=579</guid>
		<description><![CDATA[On May 23, Jeff Atwood posted an announcement to the StackOverflow blog.  The StackOverflow team was getting to work on version 1.0 of the StackExchange API.  As you know from my previous post, I&#8217;m something of a StackExchange fan.  Needless to say (though I&#8217;ll say it anyway) I was pumped (did that rhyme?) Two months later, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=daveswersky.com&amp;blog=9388197&amp;post=579&amp;subd=daveswersky&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>On May 23, Jeff Atwood <a href="http://blog.stackoverflow.com/2010/05/stack-exchange-api-contest/" target="_blank">posted</a> an announcement to the StackOverflow blog.  The StackOverflow team was getting to work on version 1.0 of the StackExchange API.  As you know from my previous post, I&#8217;m something of a StackExchange fan.  Needless to say (though I&#8217;ll say it anyway) I was pumped (did that rhyme?)</p>
<p>Two months later, I&#8217;ve created three new open-source projects based on the StackExchange API:</p>
<p><a href="http://stackapps.com/questions/930/stacklinq-a-stackexchange-linq-provider" target="_blank">StackLINQ</a>: A LINQ Provider to the StackExchange API<br />
<a href="http://stackapps.com/questions/1269/stackeddeck-watch-your-favorite-tags-tweetdeck-style" target="_blank">StackedDeck</a>:  The TweetDeck of StackExchange.  Watch questions from any and all StackExchange sites stream in by tag.<br />
<a href="http://stackapps.com/questions/1149/stackwatcher-watch-your-stackexchange-accounts" target="_blank">StackWatcher</a>:   A system tray application that watches in real-time for changes in your rep, favorites, and badge awards, and notifies you with some popup toast.</p>
<p>This effort has been an intensive and interesting experience.  I learned a TON about LINQ and Windows Presentation Foundation, WPF being the basis for StackedDeck and StackWatcher.  I won&#8217;t lie and say I did it just for the fun of it. I would love to win cool stuff for my efforts, but that&#8217;s truly not the whole deal.</p>
<p>LINQ, WPF, and Silverlight are three of my favorite Microsoft technologies.  I&#8217;ve learned a lot more by writing the StackLINQ library and the WPF apps, and I&#8217;ll be blogging and demoing my experience over the next several months, starting with StackLINQ.  StackedDeck is now version 0.9 beta.  It will be getting a major refactoring as I refine it to take better advantage of binding and MVVM.  I will probably roll StackWatcher&#8217;s functionality into StackedDeck, and will definitely be updating StackedDeck when the StackExchange API v2 is released, so you can ask and answer questions too!</p>
<p>This process will be &#8220;televised&#8221;- that is, blogged and probably made into videos.  All three projects are on BitBucket for your perusal at the links above.  Enjoy, and watch this space to follow my progress.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/daveswersky.wordpress.com/579/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/daveswersky.wordpress.com/579/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/daveswersky.wordpress.com/579/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/daveswersky.wordpress.com/579/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/daveswersky.wordpress.com/579/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/daveswersky.wordpress.com/579/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/daveswersky.wordpress.com/579/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/daveswersky.wordpress.com/579/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/daveswersky.wordpress.com/579/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/daveswersky.wordpress.com/579/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/daveswersky.wordpress.com/579/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/daveswersky.wordpress.com/579/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/daveswersky.wordpress.com/579/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/daveswersky.wordpress.com/579/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=daveswersky.com&amp;blog=9388197&amp;post=579&amp;subd=daveswersky&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://daveswersky.com/2010/08/02/my-journey-with-the-stackexchange-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0e9420fd2a6d39a3779e1d9119834bff?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">daveswersky</media:title>
		</media:content>
	</item>
		<item>
		<title>How to Get Value From StackOverflow</title>
		<link>http://daveswersky.com/2010/07/20/how-to-get-value-from-stackoverflow/</link>
		<comments>http://daveswersky.com/2010/07/20/how-to-get-value-from-stackoverflow/#comments</comments>
		<pubDate>Tue, 20 Jul 2010 14:53:46 +0000</pubDate>
		<dc:creator>Dave Swersky</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Thoughts]]></category>
		<category><![CDATA[stackexchange]]></category>
		<category><![CDATA[stackoverflow]]></category>

		<guid isPermaLink="false">http://daveswersky.com/?p=542</guid>
		<description><![CDATA[I&#8217;ve been a regular user of StackOverflow since shortly after the beta.  It helped keep me sane during a period of semi-employment.  My company was bought out and I was paid to do nothing for eight months.  I know this sounds great, but it wasn&#8217;t.  Desperately bored and wanting to do something, I spent hours [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=daveswersky.com&amp;blog=9388197&amp;post=542&amp;subd=daveswersky&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been a regular user of StackOverflow since shortly after the beta.  It helped keep me sane during a period of semi-employment.  My company was bought out and I was paid to do nothing for eight months.  I know this sounds great, but it wasn&#8217;t.  Desperately bored and wanting to do <em>something, </em>I spent hours answering SO questions.</p>
<p>Over the course of eighteen months, I&#8217;ve learned a few useful ways to get the most out of this amazing site.  I thought now would be a good time to share the best ones.</p>
<p>There are four common ways to get value from StackOverflow:</p>
<ul>
<li>Asking questions</li>
<li>Finding answers by landing on SO through a Google search</li>
<li>Finding answers by searching SO directly</li>
<li>Answering questions</li>
</ul>
<p>We&#8217;ll take each one in turn.</p>
<h2>Asking Questions</h2>
<p>Asking questions on StackOverflow is a skill.  First and foremost, questions must be <em>answerable.</em> The progenitors and maintainers of the site (Jeff, Joel, and The Community) created StackOverflow to contain <em>Questions </em>and <em>Answers, </em>not <em>Flames </em>and <em>Opinions. </em>That&#8217;s not to say the latter doesn&#8217;t happen, but subjective questions are generally closed quickly.  I have only asked a few questions on SO when I&#8217;ve been truly stuck, and have been very satisfied with the results.  Answers to well-crafted questions come quickly.</p>
<p><strong>Do:</strong></p>
<ul>
<li>Make questions concise and readable</li>
<li>Include enough information (code!!)</li>
<li>Markup code so it&#8217;s readable.  Use the ` before and after code blocks, or use the little binary button.</li>
<li>Include the steps you have already taken (no &#8220;How do I write Facebook?  Plz send the codez!&#8221;)</li>
<li><strong>Accept Answers! </strong>Answerers do pay attention to your accept rate.</li>
</ul>
<p><strong>Don&#8217;t:</strong></p>
<ul>
<li>Ask a question until you understand the problem well enough to articulate it clearly</li>
<li>Ask for help with homework unless you have tried at least ten things (and include those things)</li>
<li>Ask subjective questions.  &#8221;Why&#8221; questions are often subjective.</li>
<li>Downvote just because you disagree with an opinion, or out of retribution.  No one will know you did it, but it&#8217;s baaad karma.</li>
</ul>
<h2>Finding Answers</h2>
<p>Finding answers on SO is easy:  search Google.  Over half of my technical searches lead to SO.  Searching SO directly is useful too, but here&#8217;s a pro tip:  when you&#8217;re at your wit&#8217;s end and you start asking a question, pay attention to the questions that pop up as you enter your question title.  For some inexplicable reason, that search seems to come up with better results.  It may be that your direct SO searches should be phrased Jeopardy-style, in the form of a question.  I haven&#8217;t tried that yet.</p>
<h2>Answering Questions</h2>
<p>Here it is- the fun part.  Answering questions on SO is all about giving back to the community, helping your fellow programmer.  In a divine light of altruistic service, the Oracles of StackOverflow share their wisdom with the masses.</p>
<p>Oh, and there&#8217;s that Reputation thing too <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Honestly, earning rep for helping people is fun.  Somehow the one without the other isn&#8217;t quite the same, regardless of the fact that the reputation has no intrinsic value whatsoever.<sup>*</sup></p>
<p>So, good answers:</p>
<p><strong>Do:</strong></p>
<ul>
<li><strong>Read the Entire Question.</strong> Answers that do not take the entire question into account are often wrong and will get downvoted.</li>
<li>Use Markdown to your advantage.  Bold is great for one-liner summaries of your answer.  Italics are good for emphasis.  Use bulleted lists when appropriate.</li>
<li>Mark code appropriately, just as with questions.</li>
<li>Make the answer easy to read by inserting gaps between thoughts, even if they&#8217;re only one or two sentences.  Long paragraphs are hard to read.</li>
<li>Include enough detail to answer the question without being long-winded.</li>
<li>Focus on your area of expertise.  You shouldn&#8217;t have to research your answer except to fill in blanks.</li>
</ul>
<p><strong>Don&#8217;t:</strong></p>
<ul>
<li>Rush the answer.  Getting in first doesn&#8217;t automatically mean getting the highest-voted answer.  You can edit to add more detail later (but be careful not to write a novel, unless the question warrants a long answer)</li>
<li>Guess.  Back up your information with references.  I rarely ever post an answer without a link to supporting information.</li>
<li>Answer with just a link, unless that link is <em>exactly</em> what the poster needs.</li>
</ul>
<h2>In Summary</h2>
<p>Those are my guiding principles as I use SO.  This is certainly an incomplete list, so please leave comments and I&#8217;ll update the post with the best ideas.</p>
<p>If you enjoy answering questions on any StackExchange site, check out <a href="http://bitbucket.org/dswersky/stackwatcher/downloads">StackWatcher</a>.</p>
<div style="height:40px;"></div>
<h6><sup>*</sup>Actually, Telerik offers a free copy of their Premium Collection to answerers with over 10K reputation <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </h6>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/daveswersky.wordpress.com/542/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/daveswersky.wordpress.com/542/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/daveswersky.wordpress.com/542/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/daveswersky.wordpress.com/542/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/daveswersky.wordpress.com/542/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/daveswersky.wordpress.com/542/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/daveswersky.wordpress.com/542/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/daveswersky.wordpress.com/542/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/daveswersky.wordpress.com/542/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/daveswersky.wordpress.com/542/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/daveswersky.wordpress.com/542/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/daveswersky.wordpress.com/542/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/daveswersky.wordpress.com/542/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/daveswersky.wordpress.com/542/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=daveswersky.com&amp;blog=9388197&amp;post=542&amp;subd=daveswersky&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://daveswersky.com/2010/07/20/how-to-get-value-from-stackoverflow/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0e9420fd2a6d39a3779e1d9119834bff?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">daveswersky</media:title>
		</media:content>
	</item>
		<item>
		<title>Tagged, I&#8217;m It: My Reading List</title>
		<link>http://daveswersky.com/2010/07/15/tagged-im-it-my-reading-list/</link>
		<comments>http://daveswersky.com/2010/07/15/tagged-im-it-my-reading-list/#comments</comments>
		<pubDate>Thu, 15 Jul 2010 18:42:34 +0000</pubDate>
		<dc:creator>Dave Swersky</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Thoughts]]></category>
		<category><![CDATA[reading]]></category>

		<guid isPermaLink="false">http://daveswersky.com/?p=538</guid>
		<description><![CDATA[So I received a tag from Sara Dutkiewicz yesterday, asking that I share my reading list.  I&#8217;m a huge fan of hard science fiction, and over the years I&#8217;ve read a lot of it. I just finished Saturn&#8217;s Children by Charles Stross.  It was okay, not Stross&#8217; best work.  If you want to read great [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=daveswersky.com&amp;blog=9388197&amp;post=538&amp;subd=daveswersky&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>So I received a <a href="http://www.codinggeekette.com/post/Books-Check-Em-Out!.aspx" target="_blank">tag from Sara Dutkiewicz</a> yesterday, asking that I share my reading list.  I&#8217;m a huge fan of hard science fiction, and over the years I&#8217;ve read a lot of it.</p>
<p>I just finished <em>Saturn&#8217;s Children </em>by Charles Stross.  It was okay, not Stross&#8217; best work.  If you want to read <em>great</em> Stross, pick up:</p>
<ul>
<li><em>Singularity Sky</em></li>
<li><em>Iron Sunrise</em></li>
<li><em>Accelerando</em></li>
</ul>
<p>Before that was <em>The Unincorporated Man </em>by Dani and Eytan Kollin.  This is an <em>awesome </em>book!  I think it would make a great movie.  In the hands of a good writer and director, it could be a classic.  The next book, <em>The Unincorporated War, </em>is out in hardcover.  I&#8217;ll wait until March for the paperback- $25 is too much for a book.</p>
<p>Here is an incomplete list of my other favorite authors:</p>
<p><a href="http://www.peterfhamilton.co.uk/" target="_blank">Peter F. Hamilton</a>:  <em>Nights Dawn </em>series, <em>Nano Flower, Fallen Dragon</em></p>
<p><em></em><a href="http://www.davidbrin.com/" target="_blank">David Brin</a>: Uplift War series, <em>Kiln People</em></p>
<p><em></em><a href="http://www.gregbear.com/" target="_blank">Greg Bear</a>:  <em>Eon, Forge of God</em></p>
<p><em></em><a href="http://en.wikipedia.org/wiki/Timothy_Zahn" target="_blank">Timothy Zahn</a>:  Cobra series, Thrawn Trilogy (first Star Wars books set after episode 6)</p>
<p><a href="http://www.neilgaiman.com/" target="_blank">Neil Gaiman</a>:  <em>American Gods, Sandman, Anansi Boys</em></p>
<p><em></em><a href="http://www.stepheniemeyer.com/" target="_blank">Stephenie Meyer</a>:  <em>The Host</em>, Twilight series (yes, I read them&#8230;)</p>
<p><a href="http://en.wikipedia.org/wiki/Kim_Stanley_Robinson" target="_blank">Kim Stanley Robinson</a>:  Mars trilogy (one of my favorites), <em>Years of Rice and Salt</em></p>
<p><a href="http://www.tadwilliams.com/" target="_blank">Tad Williams</a>:  Otherland series</p>
<p><a href="http://en.wikipedia.org/wiki/Vernor_Vinge" target="_blank">Vernor Vinge</a>: <em>A Deepness in the Sky, A Fire Upon the Deep</p>
<p><a href="http://en.wikipedia.org/wiki/Robert_A._Heinlein" target="_blank"> </a></em><a href="http://en.wikipedia.org/wiki/Robert_A._Heinlein" target="_blank">Robert Heinlein</a>: <em>Stranger From a Strange Land, The Moon is a Harsh Mistress</em></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/daveswersky.wordpress.com/538/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/daveswersky.wordpress.com/538/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/daveswersky.wordpress.com/538/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/daveswersky.wordpress.com/538/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/daveswersky.wordpress.com/538/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/daveswersky.wordpress.com/538/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/daveswersky.wordpress.com/538/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/daveswersky.wordpress.com/538/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/daveswersky.wordpress.com/538/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/daveswersky.wordpress.com/538/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/daveswersky.wordpress.com/538/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/daveswersky.wordpress.com/538/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/daveswersky.wordpress.com/538/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/daveswersky.wordpress.com/538/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=daveswersky.com&amp;blog=9388197&amp;post=538&amp;subd=daveswersky&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://daveswersky.com/2010/07/15/tagged-im-it-my-reading-list/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0e9420fd2a6d39a3779e1d9119834bff?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">daveswersky</media:title>
		</media:content>
	</item>
		<item>
		<title>Entity Framework 4: Then and Now</title>
		<link>http://daveswersky.com/2010/05/26/entity-framework-4-then-and-now/</link>
		<comments>http://daveswersky.com/2010/05/26/entity-framework-4-then-and-now/#comments</comments>
		<pubDate>Thu, 27 May 2010 03:16:29 +0000</pubDate>
		<dc:creator>Dave Swersky</dc:creator>
				<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[entityframework]]></category>

		<guid isPermaLink="false">https://daveswersky.wordpress.com/?p=476</guid>
		<description><![CDATA[Contents What is OR/M? A Little History The Impedance Mismatch OR/M to the rescue Entity Framework 1.0 Entity Data Models Code Generation Generated Classes Entity Framework 1.0 FTW!…? The Controversy Persistence Ignorance Entity Framework 4 New Features Persistence Ignorance and POCO T4 Templates T4 Generated Files Model-First Development FK Associations Code-Only Entities What is Object [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=daveswersky.com&amp;blog=9388197&amp;post=476&amp;subd=daveswersky&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h4><span style="color:#000000;"><span style="text-decoration:underline;">Contents</span></span></h4>
<ul>
<li><span style="color:#000000;">What is OR/M?</span>
<ul>
<li><span style="color:#000000;">A Little History</span></li>
<li><span style="color:#000000;">The Impedance Mismatch</span></li>
<li><span style="color:#000000;">OR/M to the rescue</span></li>
</ul>
</li>
<li><span style="color:#000000;">Entity Framework 1.0</span>
<ul>
<li><span style="color:#000000;">Entity Data Models</span></li>
<li><span style="color:#000000;">Code Generation</span></li>
<li><span style="color:#000000;">Generated Classes</span></li>
<li><span style="color:#000000;">Entity Framework 1.0 FTW!…?</span></li>
</ul>
</li>
<li><span style="color:#000000;">The Controversy</span>
<ul>
<li><span style="color:#000000;">Persistence Ignorance</span></li>
</ul>
</li>
<li><span style="color:#000000;">Entity Framework 4</span>
<ul>
<li><span style="color:#000000;">New Features</span></li>
<li><span style="color:#000000;">Persistence Ignorance and POCO</span></li>
<li><span style="color:#000000;">T4 Templates</span></li>
<li><span style="color:#000000;">T4 Generated Files</span></li>
<li><span style="color:#000000;">Model-First Development</span></li>
<li><span style="color:#000000;">FK Associations</span></li>
<li><span style="color:#000000;">Code-Only Entities</span></li>
</ul>
</li>
</ul>
<h4><span style="color:#000000;"> </span></h4>
<h4><span style="color:#000000;"><span style="text-decoration:underline;">What is Object Relational Mapping?</span></span></h4>
<p><span style="color:#000000;"><strong>A Little History</strong></span></p>
<p><span style="color:#000000;">Over ten years ago, I was working a contract developing legacy ASP websites with a SQL Server 6.5 backend (on stone tablets, in the driving snow, uphill both ways…)</span></p>
<p><pre class="brush: vb;">
Set oConn = Server.CreateObject(&amp;quot;ADODB.Connection&amp;quot;)  oConn.Open &amp;quot;DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=&amp;quot; &amp;amp; Server.MapPath(&amp;quot;DB.mdb&amp;quot;)
Set rsUsers = Server.CreateObject(&amp;quot;ADODB.Recordset&amp;quot;)
rsUsers.Open(&quot;SELECT UserID FROM Users&quot;;, oConn,1,3)

--SQL CREATE PROCEDURE usp_GetCustomers () AS
...
</pre></p>
<p><span style="color:#000000;">Anyone who did this ADO development in VB6 or ASP probably noticed a trend:  <em>at least</em> 50% of your code was database-related.   Then you got to stop what you were doing writing <em>code</em>, move over to Query Analyzer, and write scads of stored procedures.   Bummer.</span></p>
<p><span style="color:#000000;">Then, in 2001, we got .NET.  Whoohoo!</span></p>
<p><pre class="brush: csharp;">
//C#
SqlDataAdapter da = new SqlDataAdapter(“usp_GetCustomer;&quot;, myConnection);
da.TableMappings.Add(&quot;Customers1&quot;, &quot;Orders&quot;);
DataSet ds = new DataSet();
da.Fill(ds, &quot;Customers&quot;);

--SQL  CREATE PROCEDURE usp_GetCustomers ()  AS
...
</pre></p>
<p><span style="color:#000000;">OK, so it’s strongly typed.  Great&#8230; but wait a minute.  The story hasn’t really changed here.  I’m still writing tons of Connections, Commands, and Parameters.  I’m still spending half my life (and my budget) hacking together repetitive SQL scripts.  Things got incrementally better with the Enterprise Library and Data Access Application Block, but the fundamental problem remained.</span></p>
<p><strong><span style="color:#000000;">What is the problem?  The Impedance Mismatch.</span></strong></p>
<p><span style="color:#000000;">“Impedance Mismatch” the clever term used to describe the fact that the Data/Persistence tier of n-tier applications was just not connecting cleanly to “upper” tiers.  Part of the reason for this was, as I’ve said, we had to work in two different languages to get anything done.  This code mismatch increased the amount of code we had to write, increased development costs, and was just no fun.</span></p>
<p><span style="color:#000000;">The other part of the impedance mismatch is the <em>Modeling Mismatch. </em>Relational databases are great for storing and retrieving data, but relational schemas don’t always make good <em>Entity Relationship Models</em>.  We needed too much code contortionism to get the relational, two-dimensional, tabular database return formats to return data in a useful, hierarchical, entity-relational manner.</span></p>
<p><strong><span style="color:#000000;">Object Relational Mapping to the rescue!</span></strong></p>
<p><span style="color:#000000;">About five years ago, some smart folks (I’m looking at you, Ayende, Rob Conery, and Frans Bouma) decided they’d had enough.  They said,</span></p>
<blockquote><p><span style="color:#000000;">I should be able to get my data by writing my queries in C#, VB.NET, or IronPython, for Pete’s sake.  I should not have to write another line of SQL.  I should be able to represent and query against <strong>Entities</strong> that contain data in the shape I need it without regard the database schema.</span></p></blockquote>
<p><span style="color:#000000;">Thus was born NHibernate, Subsonic, and LLBLGenPro.  These OR/M projects were among the first to be introduced to the .NET platform.  Through a variety of approaches, these projects:</span></p>
<ul>
<li><span style="color:#000000;">Provided the ability to <strong>abstract </strong>the database schema to a set of objects (aka Entities) whose shape did not have to match 1:1 with the tables in the database. </span></li>
<li><span style="color:#000000;">Allowed developers to write queries in the .NET language of their choice by <strong>cross-compiling </strong>queries written in C#/VB.NET <strong>directly to dynamic SQL.</strong> </span></li>
</ul>
<p><span style="color:#000000;">Not to be left out, Microsoft joined the party in 2008.  Entity Framework 1.0 was introduced with Visual Studio 2008 SP1.  In the box was:</span></p>
<ul>
<li><span style="color:#000000;">System.Data.Entity </span></li>
<li><span style="color:#000000;">A new designer for editing <strong>Entity Data Models</strong> </span></li>
<li><span style="color:#000000;">LINQ to Entities </span></li>
</ul>
<ul><span style="color:#000000;">Let’s take a quick look at Entity Framework 1.0 before we dive into EF 4.</span></ul>
<h4><span style="color:#000000;"><span style="text-decoration:underline;">Entity Framework 1.0</span></span></h4>
<p><span style="color:#000000;">The center of the story for EF 1.0 is the <strong>Entity Data Model</strong>.</span></p>
<p><a href="http://daveswersky.files.wordpress.com/2010/05/edm.jpg"><span style="color:#000000;"><img style="display:block;float:none;margin-left:auto;margin-right:auto;border-width:0;" title="edm" src="http://daveswersky.files.wordpress.com/2010/05/edm_thumb.jpg?w=515&#038;h=418" border="0" alt="edm" width="515" height="418" /></span></a><span style="color:#000000;">An Entity Data Model (EDM) is an XML-formatted file with an .edmx extension.  EDMs contain three sections: the Storage Model, Conceptual Model, and Mapping Model. </span></p>
<ul>
<li><span style="color:#000000;">The Storage model is simply an XML representation of a database schema. </span></li>
<li><span style="color:#000000;">The Conceptual model is the representation of the Entities in the EDM. </span></li>
<li><span style="color:#000000;">The Mapping Model is the map between columns in the database tables and properties of the Entities. </span></li>
</ul>
<p><span style="color:#000000;">The Entities in an EDM <em>may </em>contain data fields from a single table (Table per Type) or could be packed together in a single table (Table per Hierarchy.)  It’s also possible to split an Entity between tables.  EDMs in Entity Framework 1.0 are created as Table per Type Entities by default, which means there is one Entity per table.  It’s possible to get crazy with other mapping strategies, but it requires manually editing the .edmx file, which isn’t fun.</span></p>
<p><strong><span style="color:#000000;">Code Generation</span></strong></p>
<p><span style="color:#000000;">Creating the EDM with the designer is just one half of the excitement- the other half is the magic worked behind the scenes by the <strong>EntityModelCodeGenerator.</strong> This is a class in the Entity Framework that is used by Visual Studio to parse the .edmx file, and generates classes that reflect the shape of all the Entities in an EDM.  It uses internal logic and CodeDOM voodoo, but more on that later.</span></p>
<p><span style="color:#000000;"><strong>Generated Classes</strong></span></p>
<p><span style="color:#000000;">If you pop open the “codebehind” of a standard EF 1.0 EDM file, you’ll see an autogenerated file containing one class: the Context. </span></p>
<p><pre class="brush: csharp;">
public partial class AdventureWorksProdEntities : ObjectContext
   {
       #region Constructors
       /// &lt;summary&gt;
       /// Initializes a new AdventureWorksProdEntities object using the connection string found in the 'AdventureWorksProdEntities' section of the application configuration file.
       /// &lt;/summary&gt;
       public AdventureWorksProdEntities() : base(&quot;name=AdventureWorksProdEntities&quot;, &quot;AdventureWorksProdEntities&quot;)
       {
           this.ContextOptions.LazyLoadingEnabled = true;
           OnContextCreated();
       }
</pre></p>
<p><span style="color:#000000;">The Context is your gateway into the Entities in the EDM.  It has a few constructor overloads for accepting various connection strings or objects (the EntityConnection object.)  Then, for each Entity, a special type of property:</span></p>
<p><pre class="brush: csharp;">
[global::System.CodeDom.Compiler.GeneratedCode(&quot;System.Data.Entity.Design.EntityClassGenerator&quot;, &quot;4.0.0.0&quot;)]
        public global::System.Data.Objects.ObjectQuery&lt;Product&gt; Products
        {
            get
            {
                if ((this._Products== null))
                {
                    this._Products= base.CreateQuery&lt;Product&gt;(&quot;[Product]&quot;);
                }
                return this._Product;
            }
        }
</pre></p>
<p><span style="color:#000000;">These are not collection properties.  They are <em>query</em> properties that derive from ObjectQuery.  The Entity Framework relies on some new coolness in the System.Expressions namespace to manipulate <strong>expression trees. </strong>Expression trees allow you to represent code statements as objects.  Once you can do that, you can translate those trees into something new, like SQL.</span></p>
<p><span style="color:#000000;">Using an Entity Data Model to do all the old CRUD is super-simple:</span></p>
<p><pre class="brush: csharp;">
using (AdventureWorksProdEntities ctx = new AdventureWorksProdEntities())
{

      var products = from p in ctx.Products
                              select p;

}
</pre></p>
<p><span style="color:#000000;">We now have a <em>query</em> ready to go.  Nothing has hit the database yet.  To do that, we:</span></p>
<p><pre class="brush: csharp;">
products.ToList();
</pre></p>
<p><span style="color:#000000;">Now the query represented by expression in the LINQ statement above gets reworked by the <strong>LINQ to Entities Provider</strong> and sent to the database.  Voila, we have a populated collection!  We can get fancier:</span></p>
<p><pre class="brush: csharp;">
using (AdventureWorksProdEntities ctx = new AdventureWorksProdEntities())
{
    var products = ctx.Products.Include(“ProductSubCategory”).Select(x =&gt; x).ToList();

}
</pre></p>
<p><span style="color:#000000;"> </span></p>
<p><span style="color:#000000;"> </span></p>
<p><span style="color:#000000;">This is called <strong>eager loading</strong>.  The Include() extension method tells the Entity Framework to go ahead and get all the ProductSubCategory Entities and populate them as properties of the Product.  The “ProductSubCategory” string refers to a <em>Navigation Property </em>of Product.  Navigation Properties represent the relationships between Entities.</span></p>
<p><span style="color:#000000;">If the Include() call were not there, this would throw an exception:</span></p>
<p><pre class="brush: csharp;">
int id = products.First().ProductSubCategory.Id;
</pre></p>
<p><span style="color:#000000;">That code would throw a NullReferenceException because none of the ProductSubCategory entities are loaded.  If we don’t use Include(), we have to do this to avoid the exception:</span></p>
<p><pre class="brush: csharp;">
products.First().ProductSubCategory.Load();
</pre></p>
<p><span style="color:#000000;">That line explicitly loads the ProductSubCategory related to the first Product in the list. </span></p>
<p><span style="color:#000000;">Making and persisting changes to Entities in EF 1.0 requires just a few lines of code:</span></p>
<p><pre class="brush: csharp;">
using (AdventureWorksProdEntities ctx = new AdventureWorksProdEntities())
{
     //Assigning a different ProductSubCategory
     Product p = products.First();
     ProductSubCategory psc = ctx.ProductSubCategory.First();
     p.ProductSubCategory = psc;
     ctx.SaveChanges();
}
</pre></p>
<p><span style="color:#000000;">How many lines would this take without an OR/M?  Commands, connections, parameter objects, and all those SQL stored procedures would probably run to over 100 lines, easily.</span></p>
<p><strong><span style="color:#000000;">Entity Framework 1.0 FTW! Right?</span></strong></p>
<p><span style="color:#000000;">So, as we’ve seen, Entity Framework 1.0 is a big step forward.  What could be better? </span></p>
<p><span style="color:#000000;">A lot, actually. </span></p>
<p><span style="color:#000000;">Consider the code above.  Let’s assume the the code above reassigns one Product’s related ProductSubCategory properties to a different one that is already in the database.  We have to query for the new one and assign it to the Product, then call SaveChanges() on the Context.  Suppose we already know that the ID for the ProductSubCategory we want to assign is 16.  Why not just set the value directly and be done?  Entity Framework 1.0 just doesn’t do foreign key references that easily. </span></p>
<p><span style="color:#000000;">Difficult foreign key references, “black-box” code generation, and the limited choice between eager and explicit loading were just a few of the perceived quirks of EF 1.0. </span></p>
<p><span style="color:#000000;"> </span></p>
<h4><span style="color:#000000;"><span style="text-decoration:underline;">The Controversy</span></span></h4>
<p><span style="color:#000000;">In fact, Entity Framework 1.0 turned out to be quite controversial among the OR/M cognoscenti.  There were several features that many considered critical to a good OR/M that EF 1.0 just didn’t have.  Concern ran so high amongst these developers, that Microsoft might impose (by their estimation) a substandard platform on an unsuspecting community, that the <strong>Entity Framework Vote of No Confidence</strong> was drafted and posted online.  Over 800 developers, many of them Microsoft MVPs, signed on.  It appeared that Microsoft had work to do.</span></p>
<p><span style="color:#000000;">To be sure, the Vote of No Confidence reads like a doctoral dissertation.  It’s great for insomnia.  However, it did raise several legitimate points.  I won’t recapitulate the entire thing here, but I will call out the issue that is probably most important. </span></p>
<p><strong><span style="color:#000000;">Persistence Ignorance</span></strong></p>
<p><span style="color:#000000;">What the bleep is Persistence Ignorance?  I’m going to use a real-world example to explain.</span></p>
<blockquote><p><span style="color:#000000;">Suppose your boss comes to you and says “You, I need you to create a console app that will go to the web, read the page at the URL in the first argument, find some keywords, and save them to a file.  It will be used internally.  We’re not selling this thing, but we’ll probably need to add to it, so make sure it’s designed well enough.”</span></p>
<p><span style="color:#000000;">OK, no problem.  File-New Project, Console app.  Add reference- System.Web…</span></p></blockquote>
<p><span style="color:#000000;">Bothered yet?  You should be.  I’m about to add a static reference to System.Web in my <em>console app.</em> Bad foo.  I’m violating a few important things here, like Single Responsibility Principle and Separation of Concerns.  What should I be doing?  I should add a new class project, right?  Right.  My business logic belongs in its own assembly.  <em>That</em> assembly should get the reference to System.Web.</span></p>
<p><span style="color:#000000;">Entity Framework 1.0 had a similar problem.  Peep this:</span></p>
<p><pre class="brush: csharp;">
public partial class Product: EntityObject
{
}
</pre></p>
<p><span style="color:#000000;">This tiny little excerpt from the Context class of an EF 1.0 Entity Data Model exposes a major issue with EF 1.0.  All the Entity classes generated by an EF 1.0 EDM derive from EntityObject.  This means that my Entities are tightly, statically coupled to their persistence implementation.</span></p>
<p><span style="color:#000000;">Boo.</span></p>
<p><span style="color:#000000;">Enterprise Architectures and Service-Oriented Architectures consider this type of coupling to be an antipattern.  Entities are really just Data Transfer Objects (DTOs.)  Good architectural design dictates that DTOs <em>must not</em> have any knowledge of (i.e. direct coupling to) their persistence implementation(s).  They must be Persistence Ignorant. </span></p>
<p><span style="color:#000000;">Suppose your boss came back to you two weeks after your keyword-finding app was out in the wild, used by your colleagues every day:</span></p>
<blockquote><p><span style="color:#000000;">Great job!  Now we need it feed directly into an Oracle database, a SQL database, a MySQL database, and post out to a WCF Service.</span></p></blockquote>
<p><span style="color:#000000;">Now we see where Persistence Ignorance offers a huge benefit.  If your app tier is bound directly to the persistence layer, you now get to rewrite, refactor, and retest.  If, however, you had based the persistence operations on some interfaces, you can write each persistence implementation separately, test them, and plug them in with a Dependency Injection framework like Ninject or Spring.NET.  Done.</span></p>
<p><span style="color:#000000;">By </span><a href="http://ayende.com/blog/archive/2010/01/05/nhibernate-vs.-entity-framework-4.0.aspx"><span style="color:#000000;">many accounts</span></a><span style="color:#000000;">, Entity Framework 4 goes a long way to address the concerns voiced in the Entity Framework Vote of No Confidence.  There is certainly disagreement as to whether the new features go far enough, but it’s safe to say that no one can reasonably claim Microsoft wasn’t listening.  So, without further ado:</span></p>
<p><span style="color:#000000;"> </span></p>
<h4><span style="color:#000000;"><span style="text-decoration:underline;">Entity Framework 4</span></span></h4>
<p><strong><span style="color:#000000;"> </span></strong></p>
<p><span style="color:#000000;">The new features of Entity Framework 4 include: </span></p>
<ul>
<li><span style="color:#000000;">New Features </span>
<ul>
<li><span style="color:#000000;">Persistence Ignorance </span></li>
<li><span style="color:#000000;">POCO (Plain Old CLR Object) </span></li>
<li><span style="color:#000000;">T4 Code Generation </span></li>
<li><span style="color:#000000;">Self-Tracking Entities </span></li>
<li><span style="color:#000000;">Model-First Development </span></li>
<li><span style="color:#000000;">FK Associations </span></li>
<li><span style="color:#000000;">Code-only </span></li>
</ul>
<p><span style="color:#000000;">Let’s dig in.</span></li>
</ul>
<p><span style="color:#000000;"> </span></p>
<p><span style="color:#000000;"><strong>Persistence Ignorance and POCO<br />
</strong><br />
POCO objects, or “Plain-Old CLR Objects” are objects with no dependencies outside the basics, like System and System.Collections.  Here’s an example:</span></p>
<p><pre class="brush: csharp;">
    using System;
    using System.Collections;
    using System.Collections.Generic;

    public class Person
    {
    public int Id {get; set;}
    public string FirstName {get; set;}
    public string LastName {get; set;}
    List&lt;Product&gt; Purchases {get; set;}

    }
</pre></p>
<p><span style="color:#000000;">There’s no data-layer baggage here, just a few simple properties and a collection property of the Products this Person bought. </span></p>
<p><span style="color:#000000;">Entity Framework 4 will not only allow us to use a simple class like this, it will help us make one:</span></p>
<p><a href="http://daveswersky.files.wordpress.com/2010/05/edmcontextmenu.jpg"><span style="color:#000000;"><img style="display:block;float:none;margin-left:auto;margin-right:auto;border-width:0;" title="edmcontextmenu" src="http://daveswersky.files.wordpress.com/2010/05/edmcontextmenu_thumb.jpg?w=560&#038;h=342" border="0" alt="edmcontextmenu" width="560" height="342" /></span></a><span style="color:#000000;"> </span></p>
<p><span style="color:#000000;">The context menu on the right comes up when you right-click whitespace in an EDM.  The new Code Generation Item option raises this dialog:</span></p>
<p><a href="http://daveswersky.files.wordpress.com/2010/05/codegenerationdialog.jpg"><span style="color:#000000;"><img style="display:block;float:none;margin-left:auto;margin-right:auto;border-width:0;" title="codegenerationdialog" src="http://daveswersky.files.wordpress.com/2010/05/codegenerationdialog_thumb.jpg?w=582&#038;h=401" border="0" alt="codegenerationdialog" width="582" height="401" /></span></a><span style="color:#000000;"> </span></p>
<p><span style="color:#000000;">We have three options listed:</span></p>
<ul>
<li><span style="color:#000000;">ADO.NET EntityObject Generator </span></li>
<li><span style="color:#000000;">ADO.NET POCO Entity Generator </span></li>
<li><span style="color:#000000;">ADO.NET Self-Tracking Entity Generator </span></li>
</ul>
<p><span style="color:#000000;">These three options will generate classes for us to support our interaction with an EDM, but the mechanism is very different from what it was in EF 1.0.</span></p>
<p><strong><span style="color:#000000;">T4 Templates:  The Coolest VS2010 Feature You Never Heard About</span></strong></p>
<p><span style="color:#000000;">Instead of the EntityModelCodeGenerator, Entity Framework 4 uses <strong>T4 Templates</strong>.  T4 stands for <strong>Text Template Transformation Toolkit</strong>. This is an <em>incredibly powerful </em>feature of VS2010 that you get <em>for free.</em> T4 is used in ASP.NET MVC, Entity Framework, and other project types, and is the new preferred way to do code generation.  Details on T4 templates are way out of scope here, but I strongly recommend you look into them.  They’re the unsung hero of VS2010.</span></p>
<p><span style="color:#000000;">The important point about T4 templates is that they are just text files, so you can make them your own.  You can modify the ones that come with VS2010, or write new ones from scratch.  This puts you in complete control of the code generation process for Entity classes, or any other type of text-based file, for that matter.</span></p>
<p><span style="color:#000000;">The three options in the dialog above are T4 templates.  The EntityObject Generator creates classes in the same style as EF 1.0, with entities deriving from EntityObject.  The POCO Entity Generator and Self-Tracking Entity Generator is where things get interesting and new.</span></p>
<p><span style="color:#000000;"><strong>T4 Generated Files</strong></span></p>
<p><span style="color:#000000;">If you select <strong>ADO.NET POCO Entity Generator </strong>from the list of available templates, you’ll see this in Solution Explorer:</span></p>
<p><span style="color:#000000;"><a href="http://daveswersky.files.wordpress.com/2010/06/pocofiles.jpg"><img style="display:block;float:none;margin-left:auto;margin-right:auto;border-width:0;" title="pocofiles" src="http://daveswersky.files.wordpress.com/2010/06/pocofiles_thumb.jpg?w=244&#038;h=189" border="0" alt="pocofiles" width="244" height="189" /></a> </span></p>
<blockquote><p><span style="color:#000000;"><strong> </strong></span></p>
<p><span style="color:#000000;"><strong>Note:</strong> To get the EDM to generate using T4 templates instead of the EntityModelCodeGenerator, you must right-click the .edmx file in Solution Explorer, select Properties and clear the “Custom Tool” setting in the Properties pane.</span></p>
<p><span style="color:#000000;"> </span></p></blockquote>
<p><span style="color:#000000;">The files with the .tt extension are the templates.  The POCO generator has two: one for the Context, which does have to keep a reference to the Entity Framework, and another that generates a separate class file for each Entity, plus an additional class that defines FixupCollection&lt;T&gt;.  FixupCollection&lt;T&gt; is used as the basis for one-to-many relationship properties, such as between Customers and Orders.  The FixupCollection&lt;T&gt; base class ensures that modifications to one side of a relationship stay in synch with the other end.  For example, if you delete an Order, the Customers’ Orders collection is updated as well.</span></p>
<p><span style="color:#000000;">Here’s a look inside the generated Context:</span></p>
<p><pre class="brush: csharp;">
    public partial class AdvWorksHREntities : ObjectContext
    {
    public const string ConnectionString = “name=AdvWorksHREntities”;
    public const string ContainerName = “AdvWorksHREntities”;
    #region Constructors
    public AdvWorksHREntities()
    : base(ConnectionString, ContainerName)
    {
    this.ContextOptions.LazyLoadingEnabled = true;
    }
    public AdvWorksHREntities(string connectionString)
    : base(connectionString, ContainerName)
    {
    this.ContextOptions.LazyLoadingEnabled = true;
    }
    public AdvWorksHREntities(EntityConnection connection)
    : base(connection, ContainerName)
    {
    this.ContextOptions.LazyLoadingEnabled = true;
    }
    #endregion
    #region ObjectSet Properties
    public ObjectSet&lt;Department&gt; Departments
    {
    get { return _departments  ?? (_departments = CreateObjectSet&lt;Department&gt;(“Departments”)); }
    }
    private ObjectSet&lt;Department&gt; _departments;
    public ObjectSet&lt;Employee&gt; Employees
    {
    get { return _employees  ?? (_employees = CreateObjectSet&lt;Employee&gt;(“Employees”)); }
    }

    …
</pre></p>
<p><span style="color:#000000;">This Context looks similar to one generated by EF 1.0, with a few key differences.  Firstly, this context class contains only constructors and Entity query properties, but not the definition for the Entity classes themselves.  Separating these classes into their own files allows the Entity classes to live in an assembly that has no binding to System.Data.Entity.</span></p>
<p><span style="color:#000000;">Another key difference is that these query properties derive from ObjectSet instead of ObjectQuery.  ObjectSet derives from ObjectQuery, but also implements IObjectSet.  IObjectSet contains methods that were previously implemented by the EF 1.0 context object, such as AddObject and DeleteObject.  The upside of having these methods implemented as part of an interface is <strong>testability</strong> and <strong>composability:</strong></span></p>
<ul>
<li><span style="color:#000000;">You can mock out the methods of the interface and test the Entity classes without having to hit a database. </span></li>
<li><span style="color:#000000;">You can use the interfaces to glue together your persistence and business logic layers with a DI framework like Unity or Spring.NET.</span></li>
</ul>
<p><span style="color:#000000;">Now let’s peek inside an Entity class:</span></p>
<p><pre class="brush: csharp;">
public partial class Employee
{
#region Primitive Properties
public virtual int EmployeeID
{
get;
set;
}
public virtual string NationalIDNumber
{
get;
set;
}
public virtual int ContactID
{
get;
set;
}

…

#region Navigation Properties
public virtual ICollection&lt;EmployeeAddress&gt; EmployeeAddresses
{
get
{
if (_employeeAddresses == null)
{
var newCollection = new FixupCollection&lt;EmployeeAddress&gt;();
newCollection.CollectionChanged += FixupEmployeeAddresses;
_employeeAddresses = newCollection;
}
return _employeeAddresses;
}
set
{
if (!ReferenceEquals(_employeeAddresses, value))
{
var previousValue = _employeeAddresses as FixupCollection&lt;EmployeeAddress&gt;;
if (previousValue != null)
{
previousValue.CollectionChanged -= FixupEmployeeAddresses;
}
_employeeAddresses = value;
var newValue = value as FixupCollection&lt;EmployeeAddress&gt;;
if (newValue != null)
{
newValue.CollectionChanged += FixupEmployeeAddresses;
}
}
}
}
private ICollection&lt;EmployeeAddress&gt; _employeeAddresses;
</pre></p>
<p><span style="color:#000000;">Here we have some simple, primitive properties like EmployeeID.  We also see the definitions for the associative Navigation Properties, implemented as ICollections.  The getters and setters of these Navigation Properties include the association fixup logic.  FixupCollection&lt;T&gt; actually derives from ObservableCollection&lt;T&gt;, which has events that fire when the members of the collection change.  This is used in the POCO classes to fixup both ends of related Entities when objects are added or removed from one end or the other.</span></p>
<p><span style="color:#000000;"><strong>Convention Over Configuration</strong></span></p>
<p><span style="color:#000000;">So how does the Entity Data Model magically &#8220;know&#8221; how to handle POCO classes?  There&#8217;s no magic, just convention.  Entity Framework expects POCO classes to follow conventions, such as the ones for property names.  The property names of your POCO classes must match <em>exactly</em> to the names defined in the EDM.  If the conventions are followed to the letter, the CRUD &#8220;just works.&#8221;</span></p>
<p><span style="color:#000000;"><strong>Lazy Loading</strong></span></p>
<p><span style="color:#000000;"> </span></p>
<p><span style="color:#000000;">Now is a good time to talk about Lazy Loading.  Remember our earlier example of eager loading:</span></p>
<p><pre class="brush: csharp;">
    using (AdventureWorksProdEntities ctx = new AdventureWorksProdEntities())
    {
    var products = ctx.Products.Include(“ProductSubCategory”).Select(x =&gt; x).ToList();
    }
</pre></p>
<p><span style="color:#000000;">This query retrieves all Products <em>and</em> their related ProductSubCategory in a single query.  EF 4 introduces the ability to load related Entities “on demand”:</span></p>
<p><pre class="brush: csharp;">
    using (AdventureWorksProdEntities ctx = new AdventureWorksProdEntities())
    {
    var products = ctx.Products.ToList();
    int id = products.First().ProductSubCategory.Id;
    }
</pre></p>
<p><span style="color:#000000;">Without lazy loading, the code above would throw a NullReferenceException because the ProductSubCategory was neither pulled in with Include(), nor loaded explicitly with Load().  EF 4 allows the code above to “automatically” query for the related ProductSubCategory if it is not already loaded.  Lazy loading is “on” by default.  Here is one of the constructors in a generated POCO context class:</span></p>
<p><pre class="brush: csharp;">
public AdvWorksHREntities()
: base(ConnectionString, ContainerName)
{
this.ContextOptions.LazyLoadingEnabled = true;
}
</pre></p>
<p><span style="color:#000000;">This and all other constructors in a POCO context class has the LazyLoadingEnabled ContextOption set to true.  Accessing a related entity will automatically send a query to the database to retrieve the entity.</span></p>
<p><span style="color:#000000;">There’s a caveat here.  Take a gander:</span></p>
<p><pre class="brush: csharp;">
    using (AdventureWorksProdEntities ctx = new AdventureWorksProdEntities())
    {
    var products = ctx.Products.ToList();
    foreach (Product p in products)
    {
    Console.WriteLine(p.ProductSubCategory.Id.ToString());
    }
    }
</pre></p>
<p><span style="color:#000000;">This is a case where lazy loading can get you into trouble.  Suppose there were 100 Products in the products List&lt;Product&gt;.  The code above would result in 100 <em>additional queries,</em> one for each Product in the list.  This can get even worse in the case of one-to-many relationships.  The point to remember is that you must be very conscious in your use of lazy loading.  It can be very handy if used carefully, but it’s easy to abuse it.  This can have negative consequences for your application performance.  This is true for any OR/M, of course, but it can catch a developer upgrading from EF 1.0 unawares.<br />
</span></p>
<p><span style="color:#000000;"><strong>Self-Tracking Entities</strong></span></p>
<p><span style="color:#000000;">We’ve seen how Entity Framework 4 is better suited to Enterprise and Service-Oriented architectures due to POCO and Persistence Ignorance.  Entity Framework 4 introduces another improvement with Self-Tracking Entities.</span></p>
<p><span style="color:#000000;">Service-Oriented architectures rely on serialization to move objects across service boundaries.  If we want to send an EF 1.0 Entity across a WCF service, it must be Detached from its Context using the Detach() method.  If that Entity is modified and returned back to the service layer to be persisted, it must be attached to a Context using Attach().  Unfortunately, it doesn’t end there.  The state of the Entity must be checked and the ApplyPropertyChanges() method must also be used to synchronize the modified Entity with the existing Entity in the database.  SaveChanges() can then be used to update the database.  This all amounts to a very manual, tedious process.</span></p>
<p><span style="color:#000000;">The Self-Tracking Entity (STE) template offers an improvement to this process by including extension methods, classes, and interfaces that track an Entity’s state after it is transmitted over a service.  There is a catch however: self-tracking entities only work over WCF, and only if the destination client is running .NET 4.  This is due to the fact that the classes and interfaces that support the tracking must be available at the destination as well as the source.  So, STEs are useful in homogenous (.NET) environments but they don’t support heterogeneous environments where the destination service based on a platform other than .NET.</span></p>
<p><strong><span style="color:#000000;"> </span></strong></p>
<p><span style="color:#000000;"> </span></p>
<p><strong><span style="color:#000000;">Model-First Development</span></strong></p>
<p><span style="color:#000000;">If you’ve used EF 1.0, you’ve seen this dialog:</span></p>
<p><a href="http://daveswersky.files.wordpress.com/2010/06/newedm.jpg"><img style="display:block;float:none;margin-left:auto;margin-right:auto;border-width:0;" title="newedm" src="http://daveswersky.files.wordpress.com/2010/06/newedm_thumb.jpg?w=436&#038;h=144" border="0" alt="newedm" width="436" height="144" /></a></p>
<p><span style="color:#000000;">There hasn’t been much use for the “Empty model” until now.  EF 4 supports designing the model first, then using that model along with POCO classes.  It also supports database generation.  If you create your EDM, add Entities to it, then right-click on an empty area of the design surface:</span></p>
<p><a href="http://daveswersky.files.wordpress.com/2010/06/dbgeneration.jpg"><img style="display:block;float:none;margin-left:auto;margin-right:auto;border-width:0;" title="dbgeneration" src="http://daveswersky.files.wordpress.com/2010/06/dbgeneration_thumb.jpg?w=318&#038;h=306" border="0" alt="dbgeneration" width="318" height="306" /></a></p>
<p><span style="color:#000000;">Select “Generate Database from Model” and you’ll get a SQL script that will generate all the tables required by your EDM.</span></p>
<p><span style="color:#000000;"> </span></p>
<p><strong><span style="color:#000000;">FK Associations</span></strong></p>
<p><span style="color:#000000;">One of the big headaches with EF 1.0 was foreign key references.  Remember our code sample:</span></p>
<p><pre class="brush: csharp;">
using (AdventureWorksProdEntities ctx = new AdventureWorksProdEntities())
{
//Assigning a different ProductSubCategory
Product p = products.First();
ProductSubCategory psc = ctx.ProductSubCategory.First();
p.ProductSubCategory = psc;
ctx.SaveChanges();
}
</pre></p>
<p><span style="color:#000000;">All we’re doing here is reassigning the ProductSubCategory of a Product.  We should be able to do that just by setting the ID of the new ProductSubCategory foreign-key value on the Product, right?  Not so in EF 1.0.  As we see above, we actually have to go get an instance of the one we want to reassign to by querying. </span></p>
<p><span style="color:#000000;">This is no longer necessary in EF 4. </span></p>
<p><a href="http://daveswersky.files.wordpress.com/2010/06/fkassociation.jpg"><img style="display:block;float:none;margin-left:auto;margin-right:auto;border-width:0;" title="fkassociation" src="http://daveswersky.files.wordpress.com/2010/06/fkassociation_thumb.jpg?w=388&#038;h=198" border="0" alt="fkassociation" width="388" height="198" /></a></p>
<p><span style="color:#000000;">If you leave “Include foreign key columns in the model” checked, the foreign-key IDs become primitive properties of your entities, available for reassignment without hassle.  These properties are called “FK Associations” and brings zen back to the process of reassigning entity relationships.  EF 1.0 Associations are still included and are referred to as “Independent Associations”.</span></p>
<p><span style="color:#000000;"> </span></p>
<p><span style="color:#000000;"> </span></p>
<p><span style="color:#000000;"> </span></p>
<p><strong><span style="color:#000000;">Code-only Entities</span></strong></p>
<p><span style="color:#000000;"> </span></p>
<p><span style="color:#000000;">The Code-Only option is currently available only in <a href="http://www.microsoft.com/downloads/details.aspx?familyid=AF18E652-9EA7-478B-8B41-8424B94E3F58&amp;displaylang=en" target="_blank">CTP</a>.  The CTP includes the assembly Microsoft.Data.Entity.CTP, which provides classes that support a “zero-model” method for representing Entities.  The ADO.NET team has provided a great <a href="http://blogs.msdn.com/b/adonet/archive/2009/06/22/feature-ctp-walkthrough-code-only-for-the-entity-framework.aspx" target="_blank">walk-through</a> that takes you through the process of setting up a sample project. </span></p>
<p><span style="color:#000000;">Code-only development is similar in style to NHibernate and other OR/M tools that focus on code-based implementations.</span> <span style="color:#000000;">The idea behind “code-only” or “code-first” is that the Entity Model is expressed exclusively in code, with no .edmx file in the middle.  POCO classes represent the Entities.  Relationships and other facets are coded using EntityConfiguration&lt;T&gt;.  Once your object model is designed, the ContextBuilder&lt;T&gt; can use your Context class to generate a database for your model.  ContextBuilder&lt;T&gt; and EntityConfiguration&lt;T&gt; provide complete control over the mapping model used to generate the tables.  The Entity classes can be separated from the EF-dependent classes in true POCO style. </span></p>
<h4><span style="color:#000000;"><span style="text-decoration:underline;">Summary</span></span></h4>
<p>The major new features of EF 4 include:</p>
<ul>
<li><span style="color:#000000;">Persistence Ignorance</span></li>
<li><span style="color:#000000;">POCO support</span></li>
<li><span style="color:#000000;">T4 Code Generation</span></li>
<li><span style="color:#000000;">Model-First Development</span></li>
<li><span style="color:#000000;">FK Associations</span></li>
<li><span style="color:#000000;">Code-Only Development</span></li>
</ul>
<p><span style="color:#000000;">The <a href="http://stackoverflow.com/questions/2201355/ms-entity-framework-vs-nhibernate-and-its-derived-contribs-fluentnhibernate-lin" target="_blank">debate rages on</a> as to whether Entity Framework 4  matches its competitors.  It does seem safe to say that EF 4 is ready for prime-time, and deserves evaluation alongside alternatives such as NHibernate and LLBLGenPro.  I&#8217;ve been using EF 1.0 since it was released and I can personally say that the improvements in EF 4 save time and promote better architecture over the previous version.<br />
</span></p>
<p><span style="color:#000000;"> </span></p>
<p><span style="color:#000000;"><strong> </strong></span></p>
<p><span style="color:#000000;"><strong>References</strong></span></p>
<p><span style="color:#000000;">POCO in the Entity Framework: Part 1 &#8211; The Experience:</span><br />
<a href="http://blogs.msdn.com/b/adonet/archive/2009/05/21/poco-in-the-entity-framework-part-1-the-experience.aspx" target="_blank">http://blogs.msdn.com/b/adonet/archive/2009/05/21/poco-in-the-entity-framework-part-1-the-experience.aspx</a></p>
<p><span style="color:#000000;">What&#8217;s New and Cool in Entity Framework 4.0:</span><br />
<a href="http://www.develop.com/entityframework4" target="_blank">http://www.develop.com/entityframework4</a></p>
<p><span style="color:#000000;">Model First with the Entity Framework 4:</span><br />
<a href="http://blogs.msdn.com/b/adonet/archive/2009/11/05/model-first-with-the-entity-framework-4.aspx" target="_blank">http://blogs.msdn.com/b/adonet/archive/2009/11/05/model-first-with-the-entity-framework-4.aspx</a></p>
<p><span style="color:#000000;">Transparent Lazy Loading for Entity Framework – part 1:</span><br />
<a href="http://blogs.msdn.com/b/jkowalski/archive/2008/05/12/transparent-lazy-loading-for-entity-framework-part-1.aspx" target="_blank">http://blogs.msdn.com/b/jkowalski/archive/2008/05/12/transparent-lazy-loading-for-entity-framework-part-1.aspx</a></p>
<p><span style="color:#000000;"> </span><span style="color:#000000;">Attaching/Detaching Entities in EF 1.0: </span><a title="http://community.dynamics.com/blogs/cesardalatorre/comments/9584.aspx" href="http://community.dynamics.com/blogs/cesardalatorre/comments/9584.aspx"><span style="color:#0000ff;"></p>
<p>http://community.dynamics.com/blogs/cesardalatorre/comments/9584.asp</span></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/daveswersky.wordpress.com/476/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/daveswersky.wordpress.com/476/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/daveswersky.wordpress.com/476/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/daveswersky.wordpress.com/476/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/daveswersky.wordpress.com/476/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/daveswersky.wordpress.com/476/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/daveswersky.wordpress.com/476/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/daveswersky.wordpress.com/476/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/daveswersky.wordpress.com/476/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/daveswersky.wordpress.com/476/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/daveswersky.wordpress.com/476/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/daveswersky.wordpress.com/476/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/daveswersky.wordpress.com/476/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/daveswersky.wordpress.com/476/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=daveswersky.com&amp;blog=9388197&amp;post=476&amp;subd=daveswersky&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://daveswersky.com/2010/05/26/entity-framework-4-then-and-now/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0e9420fd2a6d39a3779e1d9119834bff?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">daveswersky</media:title>
		</media:content>

		<media:content url="http://daveswersky.files.wordpress.com/2010/05/edm_thumb.jpg" medium="image">
			<media:title type="html">edm</media:title>
		</media:content>

		<media:content url="http://daveswersky.files.wordpress.com/2010/05/edmcontextmenu_thumb.jpg" medium="image">
			<media:title type="html">edmcontextmenu</media:title>
		</media:content>

		<media:content url="http://daveswersky.files.wordpress.com/2010/05/codegenerationdialog_thumb.jpg" medium="image">
			<media:title type="html">codegenerationdialog</media:title>
		</media:content>

		<media:content url="http://daveswersky.files.wordpress.com/2010/06/pocofiles_thumb.jpg" medium="image">
			<media:title type="html">pocofiles</media:title>
		</media:content>

		<media:content url="http://daveswersky.files.wordpress.com/2010/06/newedm_thumb.jpg" medium="image">
			<media:title type="html">newedm</media:title>
		</media:content>

		<media:content url="http://daveswersky.files.wordpress.com/2010/06/dbgeneration_thumb.jpg" medium="image">
			<media:title type="html">dbgeneration</media:title>
		</media:content>

		<media:content url="http://daveswersky.files.wordpress.com/2010/06/fkassociation_thumb.jpg" medium="image">
			<media:title type="html">fkassociation</media:title>
		</media:content>
	</item>
		<item>
		<title>Now Presenting&#8230; Entity Framework 4!</title>
		<link>http://daveswersky.com/2010/05/18/now-presenting-entity-framework-4/</link>
		<comments>http://daveswersky.com/2010/05/18/now-presenting-entity-framework-4/#comments</comments>
		<pubDate>Tue, 18 May 2010 20:42:57 +0000</pubDate>
		<dc:creator>Dave Swersky</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[entityframework]]></category>
		<category><![CDATA[presenting]]></category>
		<category><![CDATA[sig]]></category>

		<guid isPermaLink="false">http://daveswersky.com/?p=450</guid>
		<description><![CDATA[I&#8217;ll be presenting &#8220;Entity Framework: Then and Now&#8221; at the Cleveland C#/VB.NET Special Interest group on Tuesday May 25th. Come heckle see me making a fool of myself brilliant presentation! http://www.clevelanddotnet.info/<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=daveswersky.com&amp;blog=9388197&amp;post=450&amp;subd=daveswersky&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div style="text-align:center;"><a href="http://www.clevelanddotnet.info/"><img class="alignnone" style="border:0 none;" src="http://www.clevelanddotnet.info/images/sig_logo.jpg" border="0" alt="" width="305" height="126" /></a></div>
<div style="height:25px;"></div>
<p>I&#8217;ll be presenting <strong>&#8220;Entity Framework: Then and Now&#8221; </strong>at the <strong>Cleveland C#/VB.NET Special Interest</strong> group on Tuesday May 25th.  Come <span style="text-decoration:line-through;">heckle</span> see me making a <span style="text-decoration:line-through;">fool of myself</span> brilliant presentation!</p>
<p><a href="http://www.clevelanddotnet.info/">http://www.clevelanddotnet.info/</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/daveswersky.wordpress.com/450/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/daveswersky.wordpress.com/450/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/daveswersky.wordpress.com/450/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/daveswersky.wordpress.com/450/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/daveswersky.wordpress.com/450/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/daveswersky.wordpress.com/450/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/daveswersky.wordpress.com/450/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/daveswersky.wordpress.com/450/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/daveswersky.wordpress.com/450/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/daveswersky.wordpress.com/450/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/daveswersky.wordpress.com/450/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/daveswersky.wordpress.com/450/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/daveswersky.wordpress.com/450/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/daveswersky.wordpress.com/450/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=daveswersky.com&amp;blog=9388197&amp;post=450&amp;subd=daveswersky&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://daveswersky.com/2010/05/18/now-presenting-entity-framework-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0e9420fd2a6d39a3779e1d9119834bff?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">daveswersky</media:title>
		</media:content>

		<media:content url="http://www.clevelanddotnet.info/images/sig_logo.jpg" medium="image" />
	</item>
		<item>
		<title>I Don&#8217;t Miss ViewState</title>
		<link>http://daveswersky.com/2010/05/16/i-dont-miss-viewstate/</link>
		<comments>http://daveswersky.com/2010/05/16/i-dont-miss-viewstate/#comments</comments>
		<pubDate>Sun, 16 May 2010 16:49:48 +0000</pubDate>
		<dc:creator>Dave Swersky</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[asp.net asp.net-mvc viewstate]]></category>

		<guid isPermaLink="false">http://daveswersky.com/?p=421</guid>
		<description><![CDATA[I’ve been working with ASP.NET MVC for the last year and I don’t miss webforms.  The one thing about webforms I miss the least is ViewState. It’s a Hack Hidden HTML fields were never intended to hold so much data.  Persisting data in the page this way is Ugly, Expensive, Confusing, and Hard to Test. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=daveswersky.com&amp;blog=9388197&amp;post=421&amp;subd=daveswersky&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div class="WordSection1">
<p class="MsoNormal">I’ve been working with ASP.NET MVC for the last year and I don’t miss webforms.  The one thing about webforms I miss the least is ViewState.</p>
<p class="MsoNormal"><strong>It’s a Hack</strong></p>
<p class="MsoNormal" style="padding-left:30px;">Hidden HTML fields were never intended to hold so much data.  Persisting data in the page this way is Ugly, Expensive, Confusing, and Hard to Test.</p>
<p class="MsoNormal"><strong>It’s Ugly</strong></p>
<p class="MsoNormal" style="padding-left:30px;">ViewState is this ugly blob of Base-64 encoded data:</p>
<pre class="MsoNormal" style="padding-left:30px;"><span style="font-family:&amp;"> &lt;input type=”hidden” name=”__VIEWSTATE”
  value=”</span>aHR0cDovL3d3dy5jb2Rlcm9zZXR0YS5jb20vYmFsbHB1enpsZQ==<span style="font-family:&amp;">” /&gt;</span></pre>
<p class="MsoNormal"><strong>It’s Expensive</strong></p>
<p class="MsoNormal" style="padding-left:30px;">ViewState is processed <em>on every postback. </em>This means it has to be sent, parsed, processed, updated, and re-sent with every request.  Not good for performance!</p>
<p class="MsoNormal"><strong>It’s Confusing</strong></p>
<p class="MsoNormal" style="padding-left:30px;">I can’t tell you how many StackOverflow and forums posts I’ve seen about dynamic controls and ViewState.  If you don’t add dynamic controls at just the right point in the page lifecycle, ViewState breaks.</p>
<p class="MsoNormal"><strong>It Uses Magic Strings (So It’s Hard to Test)</strong></p>
<p class="MsoNormal" style="padding-left:30px;"><span style="font-family:courier;">ViewState["MyMagicString"]</span> is a typo-prone way to address data.  Strongly-typed Views in ASP.NET MVC are so much easier to work with and much more testable.</p>
<p class="MsoNormal"><strong><span style="text-decoration:underline;">The MVC Way</span></strong></p>
<p class="MsoNormal" style="padding-left:30px;">MVC doesn’t even try to match ViewState as a feature.  ViewState is a stateful paradigm layered on top of a fundamentally stateless protocol: HTTP.  Rather than the hybridized hack of packing a huge encoded graph into a hidden field, MVC says:</p>
<p class="MsoNormal" style="text-indent:.5in;padding-left:30px;"><strong>“If you want to persist state, do it on the server using a Model.&#8221;</strong></p>
<p style="padding-left:30px;">You can use Session state or TempData on the server and javascript or cookies at the client to store <em>pointers</em>, but actual data should be persisted by one thing- the Model.  The MVC rendering pipeline relies on Models (or ViewModels) to retain and provide the data that populate Views.  If you change the state of a control, the data is updated in and persisted through the Model, preferably by a loosely-coupled persistence implementation.  This is a much cleaner, architecturally sound method for dealing with state over a stateless delivery protocol.</p>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/daveswersky.wordpress.com/421/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/daveswersky.wordpress.com/421/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/daveswersky.wordpress.com/421/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/daveswersky.wordpress.com/421/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/daveswersky.wordpress.com/421/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/daveswersky.wordpress.com/421/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/daveswersky.wordpress.com/421/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/daveswersky.wordpress.com/421/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/daveswersky.wordpress.com/421/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/daveswersky.wordpress.com/421/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/daveswersky.wordpress.com/421/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/daveswersky.wordpress.com/421/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/daveswersky.wordpress.com/421/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/daveswersky.wordpress.com/421/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=daveswersky.com&amp;blog=9388197&amp;post=421&amp;subd=daveswersky&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://daveswersky.com/2010/05/16/i-dont-miss-viewstate/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0e9420fd2a6d39a3779e1d9119834bff?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">daveswersky</media:title>
		</media:content>
	</item>
	</channel>
</rss>
