EntityFramework Field Driven design Practice (i): From DataTable to Entityobject

Source: Internet
Author: User

While the DataTable is technically not comparable to Entityobject, it suggests that a revolution is taking place, even with Microsoft, from the hurricane of the revolution.

The idea of software design needs revolution, and it needs to get rid of the original idea and move towards the field-oriented road. You may think it sounds very iffy, but the current situation of software development so that you have to accept the reality, still have a large gang of people all day to pull the database, still have a big help to ask: "I want to implement XXXX function, my database should be how to design?" "These are the fundamental mistakes that make the software's purpose wrong and what does the software research?" is to study how computers can be used to solve actual (domain) problems, rather than to study how data should be saved more rationally. I have said this in my previous posting many times, and I will not repeat it here.

Of course, a lot of readers will have the same opinion with me, will also feel that I am "Mars", but it does not matter, above all I said is a primer, hoping to help more "misguided" practitioners "on the Straight Path." It is true that software design should move from "database-driven" to "domain-driven", while the practical experience of domain-driven design provides practical guidance for the design and development of large and complex software systems.

Back to our subtitle, from the DataTable to the Entityobject, what do you see? What we see is Microsoft's progress in the field drive, from the sheer data organization of the DataTable to the entity of Entityobject, Microsoft brings us not only the technical framework, but also a domain-oriented solution.

. NET 4.0来, what follows is the Entity Framework (EntityFramework, referred to as "EF"), in this series, I will combine the practice of domain-driven design to analyze the specific application of EF, of course, the current EF is not so perfect, and I am very excited to see, In the future, Microsoft will continue to develop and improve EF, making it an important role in the Microsoft domain-driven toolbox.

First of all, let's briefly analyze, as a framework, what hard needs to support domain-driven thinking, and then think carefully about whether the. NET EF really works well with the domain drivers.

First, we need to be able to treat the concept of "domain model" correctly. The domain model differs from the data model in that it describes the various classes in the domain and their relationships. Class relationships are diverse, such as composition, aggregation, inheritance, implementation, constraints, and so on, and the data model is not one-to-many or many-to-many. From the perspective of domain-driven design, the database is only an external mechanism of the storage entity, which belongs to the technical level. The data model is mainly used to describe the persistence mode of domain model object, it should be the domain model first, then the data model, the domain model needs some mapping to produce the corresponding data model. Therefore, the framework must support mapping from the domain model to the data model.

Not only does EF support DDL generation of databases from the domain model, but it also supports the generation of "domain models" from the database structure. I think the latter can be removed because the database is not a domain model. You will ask why, I can tell you, pure data is no way to describe the domain concept. For example: There is a table in your database called "customer", and when you generate a "domain model" from the database structure, Visual Studio will certainly help you generate a "domain object" called customer, but if I change the name of the datasheet to "ABC", Although there is still the customer information, but the EF does not know this, but also to generate an "ABC" class, and such things can be regarded as a domain object? So the data depends on the entity, the state of the entity, and the data leaving the entity is meaningless.

The contents of the markup above, according to the domain-driven design of the idea, should not be saved. However. NET is a product that takes into account a variety of requirements, so the "generate model from the database" feature will also be preserved

Support for the "aggregation" concept. Aggregation is a set of interrelated entities that describe the same concept, such as sales orders, sales order lines, and commodities, which can be consolidated into one aggregation and the sales order as the root of the aggregation. Questions about aggregations will be discussed in subsequent articles. Why do you introduce aggregations? This is a unique way for domain-driven design to handle large software systems. There may be a lot of physical objects in a software system, and the relationship between them can be complex, so when we need to "wake" (or read) an entity object from an external persistence mechanism, do we need to read it and all of its associated objects into memory? Of course not, because we just need to focus on one aspect of the whole problem. For example, when reading customer data, we might display all of the customer's orders, but not all the order lines for each order, because now we haven't decided if we really need to see all the order lines.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.