Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Entity framework, as opposed to linq-to-sql for instance, was designed with separation between data model and conceptual model in mind. It supports <a href="http://weblogs.asp.net/manavi/archive/2010/12/24/inheritance-mapping-strategies-with-entity-framework-code-first-ctp5-part-1-table-per-hierarchy-tph.aspx" rel="nofollow noreferrer">inheritance</a>, <a href="http://blogs.microsoft.co.il/blogs/gilf/archive/2009/03/06/entity-splitting-in-entity-framework.aspx" rel="nofollow noreferrer">entity splitting</a>, <a href="http://weblogs.asp.net/manavi/associations-in-ef-4-1-code-first-part-4-table-splitting" rel="nofollow noreferrer">table splitting</a>, <a href="http://weblogs.asp.net/manavi/associations-in-ef-4-1-code-first-part-2-complex-types" rel="nofollow noreferrer">complex types</a>, and <a href="https://msdn.microsoft.com/en-us/data/jj591620#ManyToMany" rel="nofollow noreferrer">transparent many-to-many associations</a>, all of which allow moulding the domain model to one's needs without being constrained too much by the data store model.</p> <p>The code-first approach allows working with POCOs in which selected properties can be mapped to data store columns. Model-first and Database-first generate partial classes, allowing one to extend the generated code. Working with those classes largely has the look and feel of working with POCOs. Even more since version 5, when <code>DbContext</code> became the default API, so the generated classes were no longer stuffed with persistence-related code of the <code>ObjectContext</code> API.</p> <p>Of course this separation of conceptual model and store model can only succeed to a certain extent. Some things work against this goal of <em>persistence ignorance</em>. For instance, if lazy loading is desirable, it is necessary to declare navigation properties as <code>virtual</code>, so EF can override them in proxy types. And it is <em>very</em> convenient to have primitive foreign key properties (say, <code>ParentId</code>) accompanying the "real" associations (a <code>Parent</code> reference). Purists consider this a violation of domain-driven design.</p> <p>Another important violation of persistence ignorance is the large number of <a href="https://stackoverflow.com/a/13352779/861716">differences between linq-to-objects and linq-to-entities</a>. You just can't ignore the fact that you are linq-ing against a totally different universe than objects in memory. This is referred to as <a href="http://blog.ploeh.dk/2012/03/26/IQueryableTisTightCoupling/" rel="nofollow noreferrer">tight coupling, or leaky abstraction</a>.</p> <p>But then... generally I'm happy with using generated EF classes or POCOs from a code-first model as domain classes. So far, I've never seen a frictionless transition from one data store to another, if it happens at all. Persistence ignorance is a fiction. Peculiarities from the DAL always leave a footprint in the domain. Only when you have to code for different data stores/models or when stores/models are expected to change relatively often it pays off to minimize this footprint as much as possible or abstract it away completely.</p> <p>Another factor is that may promote EF classes as domain classes is that many applications today have multiple tiers, where (serialized) different view models or DTOs are sent to a client. Using domain classes in UIs hardly ever fits the bill. You may as well use the EF classes as domain and have services throw out dedicated models and DTOs as required by a UI or service consumers. Another abstraction layer may be more of a burden than a blessing, if only performance-wise.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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