<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" version="2.0">
  <channel>
    <title>Dan Miser - EntityFramework</title>
    <link>http://www.distribucon.com/blog/</link>
    <description>Thoughts from Dan Miser</description>
    <language>en-us</language>
    <copyright>Dan Miser</copyright>
    <lastBuildDate>Wed, 15 Feb 2012 00:55:59 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.9074.18820</generator>
    <managingEditor>dmiser@distribucon.com</managingEditor>
    <webMaster>dmiser@distribucon.com</webMaster>
    <item>
      <trackback:ping>http://www.distribucon.com/blog/Trackback.aspx?guid=06edb1e9-68c8-44cf-81ae-2e2ba020225e</trackback:ping>
      <pingback:server>http://www.distribucon.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.distribucon.com/blog/PermaLink,guid,06edb1e9-68c8-44cf-81ae-2e2ba020225e.aspx</pingback:target>
      <dc:creator>Dan Miser</dc:creator>
      <wfw:comment>http://www.distribucon.com/blog/CommentView,guid,06edb1e9-68c8-44cf-81ae-2e2ba020225e.aspx</wfw:comment>
      <wfw:commentRss>http://www.distribucon.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=06edb1e9-68c8-44cf-81ae-2e2ba020225e</wfw:commentRss>
      <slash:comments>8</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">I had a class that looked like this:<br /><pre><code> public class CollectionDetail { public int Id { get; set; } ... public
MachineField MachineField { get; set; } } </code></pre><p>
I would then later write LINQ code that would end up retrieving these objects. The
problem was MachineField was always set to null. I banged my head on this for a long
time looking at everything I could think of. Finally, after looking at the CollectionDetail
class one more time, I noticed that other Foreign Key objects were marked with virtual,
and I remembered that I removed virtual while I was trying to test whether or not
the object's lazy load behavior. All of the documentation clearly states that you
need to mark this virtual. Once I added the virtual keyword back, everything worked
exactly as it should have.
</p><img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=06edb1e9-68c8-44cf-81ae-2e2ba020225e" /></body>
      <title>Entity Framework CodeFirst: virtual is sort of important</title>
      <guid isPermaLink="false">http://www.distribucon.com/blog/PermaLink,guid,06edb1e9-68c8-44cf-81ae-2e2ba020225e.aspx</guid>
      <link>http://www.distribucon.com/blog/EntityFrameworkCodeFirstVirtualIsSortOfImportant.aspx</link>
      <pubDate>Wed, 15 Feb 2012 00:55:59 GMT</pubDate>
      <description>I had a class that looked like this:&lt;br&gt;
&lt;pre&gt;&lt;code&gt; public class CollectionDetail { public int Id { get; set; } ... public
MachineField MachineField { get; set; } } &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
I would then later write LINQ code that would end up retrieving these objects. The
problem was MachineField was always set to null. I banged my head on this for a long
time looking at everything I could think of. Finally, after looking at the CollectionDetail
class one more time, I noticed that other Foreign Key objects were marked with virtual,
and I remembered that I removed virtual while I was trying to test whether or not
the object's lazy load behavior. All of the documentation clearly states that you
need to mark this virtual. Once I added the virtual keyword back, everything worked
exactly as it should have.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.distribucon.com/blog/aggbug.ashx?id=06edb1e9-68c8-44cf-81ae-2e2ba020225e" /&gt;</description>
      <comments>http://www.distribucon.com/blog/CommentView,guid,06edb1e9-68c8-44cf-81ae-2e2ba020225e.aspx</comments>
      <category>.NET</category>
      <category>EntityFramework</category>
    </item>
  </channel>
</rss>