[{"data":1,"prerenderedAt":164},["ShallowReactive",2],{"blog:2007:linq-to-sql-nullreferenceexception-on-submitchanges":3,"blogMore-Development":150,"comments-linq-to-sql-nullreferenceexception-on-submitchanges":163},{"id":4,"title":5,"body":6,"category":133,"commentCount":117,"date":134,"description":12,"excerpt":135,"extension":136,"filenames":137,"hidden":138,"image":137,"meta":139,"minutes":63,"navigation":140,"path":141,"seo":142,"showCategory":137,"stem":143,"tags":144,"updated":137,"url":147,"wordCount":148,"__hash__":149},"content\u002Fblog\u002F2007\u002Flinq-to-sql-nullreferenceexception-on-submitchanges.md","LINQ to SQL NullReferenceException on SubmitChanges",{"type":7,"value":8,"toc":131},"minimark",[9,13,16,27,121,127],[10,11,12],"p",{},"I’ve been busy working on some LINQ to SQL (formerly DLINQ) apps that have been going well bar a NullReferenceException thrown at me from deep in the bowels of LINQ and it’s change tracker. A cursory glance in debug showed none of the properties that represent columns were null…",[10,14,15],{},"The null was actually a collection property that represented a one-to-many relationship that was automatically created using the foreign key constraints in the database. Normally this is set to an empty EntitySet however I was failing to call the default constructor from my new useful constructor.",[10,17,18,19,26],{},"The moral of the story is always call the default constructor with this(), especially when extending generated code. So much for ",[20,21,25],"a",{"href":22,"rel":23},"https:\u002F\u002Fiancooper.spaces.live.com\u002Fblog\u002Fcns%21844BD2811F9ABE9C%21397.entry",[24],"nofollow","persistence ignorance",".",[28,29,34],"pre",{"className":30,"code":31,"language":32,"meta":33,"style":33},"language-csharp shiki shiki-themes everforest-light dracula","public partial class Invoice {\n  public Invoice(int number) : this() {\n    this.number = number;\n  }\n}\n","csharp","",[35,36,37,61,91,109,115],"code",{"__ignoreMap":33},[38,39,42,46,49,53,57],"span",{"class":40,"line":41},"line",1,[38,43,45],{"class":44},"s9HRq","public",[38,47,48],{"class":44}," partial",[38,50,52],{"class":51},"smiwp"," class",[38,54,56],{"class":55},"sPLAf"," Invoice",[38,58,60],{"class":59},"s6Vpi"," {\n",[38,62,64,67,70,73,77,81,84,88],{"class":40,"line":63},2,[38,65,66],{"class":44},"  public",[38,68,56],{"class":69},"sS4Kt",[38,71,72],{"class":59},"(",[38,74,76],{"class":75},"sXAHl","int",[38,78,80],{"class":79},"s7cAX"," number",[38,82,83],{"class":59},") : ",[38,85,87],{"class":86},"sKO3f","this",[38,89,90],{"class":59},"() {\n",[38,92,94,97,99,103,106],{"class":40,"line":93},3,[38,95,96],{"class":86},"    this",[38,98,26],{"class":59},[38,100,102],{"class":101},"sSKRk","number",[38,104,105],{"class":44}," =",[38,107,108],{"class":59}," number;\n",[38,110,112],{"class":40,"line":111},4,[38,113,114],{"class":59},"  }\n",[38,116,118],{"class":40,"line":117},5,[38,119,120],{"class":59},"}\n",[10,122,123],{},[124,125,126],"em",{},"[)amien",[128,129,130],"style",{},"html pre.shiki code .s9HRq, html code.shiki .s9HRq{--shiki-default:#F57D26;--shiki-dark:#FF79C6}html pre.shiki code .smiwp, html code.shiki .smiwp{--shiki-default:#F85552;--shiki-dark:#FF79C6}html pre.shiki code .sPLAf, html code.shiki .sPLAf{--shiki-default:#3A94C5;--shiki-dark:#8BE9FD}html pre.shiki code .s6Vpi, html code.shiki .s6Vpi{--shiki-default:#5C6A72;--shiki-dark:#F8F8F2}html pre.shiki code .sS4Kt, html code.shiki .sS4Kt{--shiki-default:#8DA101;--shiki-dark:#50FA7B}html pre.shiki code .sXAHl, html code.shiki .sXAHl{--shiki-default:#3A94C5;--shiki-dark:#FF79C6}html pre.shiki code .s7cAX, html code.shiki .s7cAX{--shiki-default:#5C6A72;--shiki-default-font-style:inherit;--shiki-dark:#FFB86C;--shiki-dark-font-style:italic}html pre.shiki code .sKO3f, html code.shiki .sKO3f{--shiki-default:#DF69BA;--shiki-default-font-style:inherit;--shiki-dark:#BD93F9;--shiki-dark-font-style:italic}html pre.shiki code .sSKRk, html code.shiki .sSKRk{--shiki-default:#35A77C;--shiki-dark:#F8F8F2}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":33,"searchDepth":63,"depth":63,"links":132},[],"Development","2007-06-11T17:27:56+00:00","[object Object]","md",null,false,{},true,"\u002Fblog\u002F2007\u002Flinq-to-sql-nullreferenceexception-on-submitchanges",{"title":5,"description":12},"blog\u002F2007\u002Flinq-to-sql-nullreferenceexception-on-submitchanges",[145,146],".NET","LINQ","\u002Fblog\u002F2007\u002Flinq-to-sql-nullreferenceexception-on-submitchanges\u002F",231,"dQiLhLTprAozjdElZAHUepL08FJO6kG7CnKuljcdVXs",[151,155,159],{"title":152,"date":153,"url":154},"Transactions in the MongoDB EF Core Provider","2025-10-25","\u002Fblog\u002F2025\u002Fmongodb-explicit-transactions\u002F",{"title":156,"date":157,"url":158},"Queryable Encryption with the MongoDB EF Core Provider","2025-09-22","\u002Fblog\u002F2025\u002Fmongodb-queryable-encryption\u002F",{"title":160,"date":161,"url":162},"Lazy Loading with EF Core Proxies","2025-04-02","\u002Fblog\u002F2025\u002Fef-proxies\u002F",[],1780900532020]