<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: LINQ to SQL NullReferenceException on SubmitChanges</title>
	<atom:link href="http://damieng.com/blog/2007/06/11/linq-to-sql-nullreferenceexception-on-submitchanges/feed" rel="self" type="application/rss+xml" />
	<link>http://damieng.com/blog/2007/06/11/linq-to-sql-nullreferenceexception-on-submitchanges</link>
	<description>A .NET developer in Redmond</description>
	<lastBuildDate>Sun, 14 Mar 2010 14:22:22 -0800</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Andrei Rinea</title>
		<link>http://damieng.com/blog/2007/06/11/linq-to-sql-nullreferenceexception-on-submitchanges#comment-11031</link>
		<dc:creator>Andrei Rinea</dc:creator>
		<pubDate>Tue, 03 Feb 2009 14:47:26 +0000</pubDate>
		<guid isPermaLink="false">http://damieng.com/blog/archive/2007/06/11/linq-to-sql-nullreferenceexception-on-submitchanges.aspx#comment-11031</guid>
		<description>Wow... I wish I read your blog entry a few weeks ago because it would have saved me a lot of headaches and I wouldn&#039;t had to write a (separate - but pretty much the same) blog entry... ( http://andreir.wordpress.com/2009/01/30/linq-to-sql-nullreferenceexception-gotcha/ )</description>
		<content:encoded><![CDATA[<p>Wow&#8230; I wish I read your blog entry a few weeks ago because it would have saved me a lot of headaches and I wouldn&#8217;t had to write a (separate &#8211; but pretty much the same) blog entry&#8230; ( <a href="http://andreir.wordpress.com/2009/01/30/linq-to-sql-nullreferenceexception-gotcha/" rel="nofollow">http://andreir.wordpress.com/2009/01/30/linq-to-sql-nullreferenceexception-gotcha/</a> )</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Damien Guard</title>
		<link>http://damieng.com/blog/2007/06/11/linq-to-sql-nullreferenceexception-on-submitchanges#comment-1865</link>
		<dc:creator>Damien Guard</dc:creator>
		<pubDate>Thu, 14 Jun 2007 08:20:46 +0000</pubDate>
		<guid isPermaLink="false">http://damieng.com/blog/archive/2007/06/11/linq-to-sql-nullreferenceexception-on-submitchanges.aspx#comment-1865</guid>
		<description>I haven&#039;t encountered the problems you describe but then I&#039;m not sold on TDD during prototyping stages. &lt;br /&gt;&lt;br /&gt;There isn&#039;t coupling between the LINQ to SQL generated and your own code at an entity level - the properties are just there and thanks to partial classes you don&#039;t even have to ever look at the source.&lt;br /&gt;&lt;br /&gt;I see ORM as commoditising, as part of the toolset and environment. As such I rely on higher-level tests to expose any flaws in the ORM just as I wouldn&#039;t test parts of the .NET framework directly to make sure lists and math work.&lt;br /&gt;&lt;br /&gt;I can understand the extra level of abstraction required when modelling objects against legacy systems or for very complex environments but in many of the recent projects I&#039;ve worked on there has been a 1:1 relationship between the database and objects.&lt;br /&gt;&lt;br /&gt;[)amien</description>
		<content:encoded><![CDATA[<p>I haven&#8217;t encountered the problems you describe but then I&#8217;m not sold on TDD during prototyping stages. </p>
<p>There isn&#8217;t coupling between the LINQ to SQL generated and your own code at an entity level &#8211; the properties are just there and thanks to partial classes you don&#8217;t even have to ever look at the source.</p>
<p>I see ORM as commoditising, as part of the toolset and environment. As such I rely on higher-level tests to expose any flaws in the ORM just as I wouldn&#8217;t test parts of the .NET framework directly to make sure lists and math work.</p>
<p>I can understand the extra level of abstraction required when modelling objects against legacy systems or for very complex environments but in many of the recent projects I&#8217;ve worked on there has been a 1:1 relationship between the database and objects.</p>
<p>[)amien</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ian Cooper</title>
		<link>http://damieng.com/blog/2007/06/11/linq-to-sql-nullreferenceexception-on-submitchanges#comment-1864</link>
		<dc:creator>ian Cooper</dc:creator>
		<pubDate>Thu, 14 Jun 2007 04:42:42 +0000</pubDate>
		<guid isPermaLink="false">http://damieng.com/blog/archive/2007/06/11/linq-to-sql-nullreferenceexception-on-submitchanges.aspx#comment-1864</guid>
		<description>Code generation comes with its own difficulties. It&#039;s difficult to use with TDD; the coupling between your code and the generated code causes a &#039;ripple of changes&#039;; and merging between versions becomes difficult.&lt;br /&gt;&lt;br /&gt;The point of coding a PI domain and then implementing the mapping once you are happy is that your changes flow from the domain out to the DB, not the other way. You don&#039;t need to remember to modify the the map  for DB changes, because you don&#039;t change that first. Instead you write tests to persist the entity, once you are happy with its domain representation.&lt;br /&gt;&lt;br /&gt;Its the tests that preserve correctness - not the tooling.&lt;br /&gt;</description>
		<content:encoded><![CDATA[<p>Code generation comes with its own difficulties. It&#8217;s difficult to use with TDD; the coupling between your code and the generated code causes a &#8216;ripple of changes&#8217;; and merging between versions becomes difficult.</p>
<p>The point of coding a PI domain and then implementing the mapping once you are happy is that your changes flow from the domain out to the DB, not the other way. You don&#8217;t need to remember to modify the the map  for DB changes, because you don&#8217;t change that first. Instead you write tests to persist the entity, once you are happy with its domain representation.</p>
<p>Its the tests that preserve correctness &#8211; not the tooling.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Damien Guard</title>
		<link>http://damieng.com/blog/2007/06/11/linq-to-sql-nullreferenceexception-on-submitchanges#comment-1863</link>
		<dc:creator>Damien Guard</dc:creator>
		<pubDate>Wed, 13 Jun 2007 21:54:16 +0000</pubDate>
		<guid isPermaLink="false">http://damieng.com/blog/archive/2007/06/11/linq-to-sql-nullreferenceexception-on-submitchanges.aspx#comment-1863</guid>
		<description>Writing manual code to perform the data mapping is cumbersome, prone to error, repetitive and is often forgotten or overlooked when making DB changes.&lt;br /&gt;&lt;br /&gt;The other extreme is a run-time layer which attempts to map using metadata. This really can introduce a black-box that may not scale, move with your technology or provide hidden gotchas at runtime you can&#039;t get a handle on.&lt;br /&gt;&lt;br /&gt;Code generation is a good compromise between these two and I have been using custom CodeSmith templates for some time.&lt;br /&gt;&lt;br /&gt;Linq to SQL keeps the code generation light and restricted to a datacontext and entity classes.  The data mapper/table classes use metadata on the entity classes. &lt;br /&gt;&lt;br /&gt;The entity classes are pure property-only mappings of the fields as you would expect. The exception to this rule is the one-to-many relationship which requires a wrapper to resolve the relationship and it is this that requires the default constructor to be called.&lt;br /&gt;&lt;br /&gt;The whole issue could be resolved if the designer/SQLMetal just made these properties construct inline as part of the definition.&lt;br /&gt;&lt;br /&gt;[)amien</description>
		<content:encoded><![CDATA[<p>Writing manual code to perform the data mapping is cumbersome, prone to error, repetitive and is often forgotten or overlooked when making DB changes.</p>
<p>The other extreme is a run-time layer which attempts to map using metadata. This really can introduce a black-box that may not scale, move with your technology or provide hidden gotchas at runtime you can&#8217;t get a handle on.</p>
<p>Code generation is a good compromise between these two and I have been using custom CodeSmith templates for some time.</p>
<p>Linq to SQL keeps the code generation light and restricted to a datacontext and entity classes.  The data mapper/table classes use metadata on the entity classes. </p>
<p>The entity classes are pure property-only mappings of the fields as you would expect. The exception to this rule is the one-to-many relationship which requires a wrapper to resolve the relationship and it is this that requires the default constructor to be called.</p>
<p>The whole issue could be resolved if the designer/SQLMetal just made these properties construct inline as part of the definition.</p>
<p>[)amien</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ian Cooper</title>
		<link>http://damieng.com/blog/2007/06/11/linq-to-sql-nullreferenceexception-on-submitchanges#comment-1862</link>
		<dc:creator>Ian Cooper</dc:creator>
		<pubDate>Wed, 13 Jun 2007 18:45:35 +0000</pubDate>
		<guid isPermaLink="false">http://damieng.com/blog/archive/2007/06/11/linq-to-sql-nullreferenceexception-on-submitchanges.aspx#comment-1862</guid>
		<description>Hi Damien,&lt;br /&gt;&lt;br /&gt;The trick for PI is not to use the designer generated code, but start with a clean class and then map manually. The code generation from LINQ to SQL produces a &#039;fat&#039; solution to the problem, with optimizations that you may not want to take until you know you need them.&lt;br /&gt;&lt;br /&gt;If you want clean code, follow the TDD approach and write it yourself. A lot of code generation is fast food - quick and cheap - but filled with nasty additives that damage your long term health.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;</description>
		<content:encoded><![CDATA[<p>Hi Damien,</p>
<p>The trick for PI is not to use the designer generated code, but start with a clean class and then map manually. The code generation from LINQ to SQL produces a &#8216;fat&#8217; solution to the problem, with optimizations that you may not want to take until you know you need them.</p>
<p>If you want clean code, follow the TDD approach and write it yourself. A lot of code generation is fast food &#8211; quick and cheap &#8211; but filled with nasty additives that damage your long term health.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
