The Entity structure, in contrast to linq-to-sql, for example, was developed taking into account the separation of the data model and the conceptual model. It supports inheritance , object splitting, table splitting , complex types and transparent many-to-many associations , all of which allow you to format the domain model to meet your needs without limiting the data warehouse model too much.
The first code approach allows you to work with POCO, in which the selected properties can be mapped to columns of the data warehouse. First, Model-first and Database-first generate partial classes, allowing you to extend the generated code. Working with these classes is largely related to the work of POCOs. Even more since version 5, when DbContext became the standard API, so the generated classes were no longer DbContext with persistence-related code in the ObjectContext API.
Of course, this separation of the conceptual model and the store model can only be achieved to a certain extent. Some things work against this goal of maintaining ignorance. For example, if lazy loading is required, you need to declare the navigation properties as virtual , so EF can override them in proxy types. And it’s very convenient to have primitive properties of a foreign key (for example, ParentId ) that accompany the “real” associations (a Parent reference). Purists consider this a violation of domain-driven rules.
Another important violation of persistence in ignorance is the large number of differences between linq-to-objects and linq-to-entity . You simply cannot ignore the fact that you are connected with a completely different universe than with objects in memory. This is called a tight connection or fuzzy abstraction .
But then ... in general, I am pleased to use the generated EF or POCOs classes from the first code model as domain classes. So far, I have never seen a transition to friction from one data warehouse to another, if at all. Maintaining ignorance is fiction. DAL features always leave a mark on the field. Only when you need to code different data warehouses / models or when stores / models are expected to change relatively often, does it pay off in order to minimize this footprint or completely abstract it.
Another factor that can contribute to EF classes in domain classes is that many applications today have several levels where (serialized) different view models or DTOs are sent to the client. Using domain classes in user interfaces is hardly ever suitable for an account. You can also use EF classes as a domain and provide services to highlight dedicated models and DTOs, as required by the user interface or service users. Another layer of abstraction may be more of a burden than a blessing, if only in terms of productivity.
Gert Arnold Jan 15 '13 at 20:05 2013-01-15 20:05
source share