anemia model; DTO: Data Transfer Object (data Transfer objects); AutoMapper;D omain model (domain models);DDD (Domain driven design)

Source: Internet
Author: User

====================== my own understanding of ==========================

A: DTO my own understanding, that is, you have a class, with the database table structure is the same, the primary key foreign keys and so on, but this model class, when you return data to the UI layer, some of the data is not used, you have to new a class to come out, the new class from the old class to get the value, And then to others to use is the new category, a bit like we do interface to Android phone with the same, the database class and interface with the class, very similar, but a lot less things, this new class (missing arm broken leg), only used to pass data, is the DTO data transfer object

Two: AutoMapper: This is a tool that can be used to help you put old classes and new classes into a data insinuate. The old category and the new category may be different, such as the old category

A book, there are multiple authors, each author, has its own name and address, if I want to return to the Android interface a JSON list, each row of data is the book, and the book has the author and author of the address

Then the returned class is probably a list of this class, and we can use AutoMapper to help us map the relationship.

Three: Domain model (domain models): What is this thing again?

Four: What is DDD?

======================= Recommended Answers ========================

Some ORM frameworks, when using entity, have some open source code that uses automapper (such as nopcommence) to turn data objects into DTOs. For example, in ORM, the model models that interact with the database are the methods of the God horse with many attribute variables. And when we interact with other systems (or other structures in the system) for coupling considerations or security considerations or performance considerations (in short, all sorts of considerations), we don't want to pass the model models directly to them, and we create an anemic model to hold the data and pass it on. The god horse is the anemia model? Anemia model (Dto,data Transfer object) that only contains the attributes of the horse, only the necessary data can be saved, there is no other redundant method of data or anything, specifically for data transfer with the type object. In this process of creation, if we do this manually, we will see this code:
b b=new B (); b.xxx1=a.xxx1;b.xxx2=a.xxx2; ..... return B;


At this point, the role of AutoMapper is to automatically map a model to a completely new B model, based on the model of a and the definition in Model B. Access-based control or consideration from the model itself. The principle of opening up is to minimize system coupling, otherwise the internal changes of all external interfaces are followed by changes; In addition, some data or methods inside the system do not want to be seen or called externally. There are a lot of similar considerations, just to cite an example. The principle of system design is high cohesion and low coupling, as far as possible rely on abstraction and not rely on the specific. The sense of automapper here is to make it easier for a database entity to convert an external calling entity (without assigning a property to an attribute).
For example 1: The database has a user information table, for other system calls, provides a data interface. If the database layer's table structure is exposed directly, it will become dependent on the system itself. In particular, assuming that, for some reason now, 10 fields of information have been added to the user's information, it would cause all modules based on this user's data structure to be collectively hung up (interface contract changes) without a type mapping. If a mapping is used, we can convert it internally, keep the original interface intact and provide a new, more comprehensive interface, which guarantees the maintainability and mobility of the system.

For example 2: A Web application collects the user's input from the front end as a dto, then transforms the DTO into a domain model and persists into the database. Conversely, when a user requests data, we need to do the opposite: the domain model that is queried from the database is converted to a dto in the opposite way and presented to the user. Use AutoMapper (a powerful Object-object mapping tool) to implement this transformation.
can refer to the following  http://www.cnblogs.com/jobs2/p/3503990.html

Love is easy, easy to get along with: When EntityFramework fall in love with AutoMapper

The marriage is easy, the dying is not easy: entityframework and AutoMapper married life

AutoMapper Reference Documentation:

    • "automapper official Documents" DTO and Domin model convert (UP)
    • "automapper Official document" DTO and Domin model to each other (middle)
    • " AutoMapper Official document "DTO and Domin model mutual conversion (bottom)
Related Article

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.