Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<h3>Virtual vs. Final properties:</h3> <p>This has really nothing to do with code first, it's the topic of EF and POCOs: When you have POCOs you lose a bunch of EF supports for your navigation properties and you can opt in to them by making them virtual. This lets EF to make a proxy at runtime and give you the support by overriding the nav properties in that proxy class. Those supports are <em>Change Notification</em>, <em>Relationship Fixup</em> and <em>Lazy Loading</em>. </p> <p>Lazy Loading works the same for Collection and non Collection type navigation properties. Also it's considered to be a <em>good practice</em> to always mark your navigation properties as virtual.</p> <h3>Foreign Key Association or Independent Associations</h3> <p>EF3.5 does not support FKs in the associations and makes them hidden (a.k.a <em>Independent Associations</em>). EF4 starts to support FKs in the associations (a.k.a <em>Foreign Key Association</em>). Depend on which one you like, you can explicitly include or not include FK properties, but it's definitely a good practice to explicitly specify FK properties, in addition to navigation properties since it gives you ultimate flexibility to work with your objects.</p> <blockquote> <p>Upon retrieval, myAccountInstanceFromDb.Owner is null. Why is that? How do I tell EF that it should do its magic and populate my Owner property?</p> </blockquote> <p>Of course, you didn't marked it as virtual so Lazy Loading is not supported yet you did not explicitly eager load or defer load it as well. To resolve that either use <em>virtual</em> keyword and let EF lazy load it for you or use <em>Include</em> method to eager load it at the time the whole object is materialized.</p> <h3>Scalar properties vs. Navigation properties</h3> <p><em>Scalar properties</em> are properties whose values are literally contained in the entity and correspond with the table columns (e.g. Account.Id). <br> <em>Navigation properties</em> are merely <em>pointers</em> to the related entities. For example the Account entity has an Owner property that will enable the application to navigate from an Account to the Owner that owns that Account. <br> So, back to your question, all you need to do is to specify a navigation property as <code>virtual Person Owner</code> and <em>optionally</em> specify a FK property as <code>int OwnerId</code> and you are good to go. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload