AutoMapper know how much?

Source: Internet
Author: User

1. Background of the event

The initial automapper is in the Performance management System 1.0, at that time because the system adopted the framework of WCF+MVC+EASYUI+EF, then we have to implement the entity transformation between the B layer and the WCF layer by means of a method (implemented in pure code) or some kind of tool implementation , I take the latter, because whenever I encounter a problem, I always feel that there is a more concise method than writing pure code.

At that time, I just looked up an example on the Internet and didn't think about that much else. Until today one of my group's partners let me debug a mistake before I really realized that my own was in need of in-depth research.

At the beginning of a project, for the framework and business analysis is not so clear conditions, most people use by the Entity Division rather than the division of business, it is estimated that some people want to save time, That is the use of the model layer of the various entities directly defined to the data contract or we said to provide the UI for display of the usage of the ViewModel, but such a result is accidental, if there is no primary foreign key relationship or other complex method of the relationship, So the direct introduction of AutoMapper will not be an error, but if you have a complex primary foreign key relationship or some other complex method, then direct introduction without configuration, there may be a lot of errors, such as "Miss type map Configuration or unsurported "and so on.

A complex primary foreign key relationship is found in the entity that will be displayed for the UI at this point, and when commented out, the problem is resolved. Let's meet AutoMapper.

2. How much does automapper know? ? What is AutoMapper 

When we learned about EF, we knew that an ORM (Object Relational Mapping) mapping is a mapping of object relationships, and object-relational mapping (ORM) systems generally exist in the form of middleware, which mainly implements the mapping of program objects to relational database data.

  While AutoMapper is a model of entity transformation Relationships, AutoMapper is a. NET object mapping tool. The main role is to perform transformations between domain objects and anemia models (DTOS), and database query results are mapped to entity objects.

? What is a dto? Concept  

Data Transfer Object (DTO) (DataTransfer object) is a software application system for transferring data between design patterns. The data transfer destination is often the object that retrieves data from the database. the difference between a data transfer object and an object or data Access object is a data (access and accessor) that does not have any behavior other than storing and retrieving it.

why use?   

Quoting the words of others "the presentation layer interacts with the application layer through a data transfer object (DTO) , which is a poco (Plain old CLR Object) object that has no behavior. Its purpose is only to encapsulate the data of domain objects, and to implement the data transfer between layers. Why can't I use a domain object directly for data transfer? Because domain objects focus more on the field, dtos pay more attention to data . Not only that, because of the "rich domain Model" characteristics, this will directly expose the behavior of the domain object to the performance layer.

What you need to know is that the data transfer object DTO itself is not a business object. Data transfer objects are designed according to the needs of the UI , not by Domain objects . For example, the customer domain object may contain information such as FirstName, LastName, Email, address, and so on. However, if the address information is not intended to be displayed on the UI, there is no need to include this address data in Customerdto.

? What is a domain object?   Concept  

A domain model is a visual representation of a conceptual class or a real-world object within a domain. Also called conceptual model, domain object model, analytical object model. It focuses on analyzing the problem areas themselves, discovering important business domain concepts, and establishing relationships between business domain concepts.

Domain model is object-oriented, an important point of object-oriented is: "To the most suitable class to do", that is: "You have to jump between the domain classes to find out how they interact." In our system model (the entity in EF) is the domain model object. domain objects are primarily business-based, and we define the model through our business.

? How to use it?   

This online information is very rich, we can search the Internet, for one thing, others told you have this thing, the rest is to learn from their own, to recommend a blog

Http://www.cnblogs.com/smileberry/p/3838143.html.

3. Summary

The domain model objects we define, such as model oriented business, and DTOs (which are data contracts in our system or ViewModel are for UI use) are UI-oriented, so we should define them according to the needs of the UI. Using DTOs allows the presentation layer to be decoupled from the model, and the presentation layer (that is, the displayed interface) does not need to refer to model, so the benefit is that even if our model or models change, and the interface does not need to change, we can directly modify the model without changing the display of the interface, This is the realization of understanding coupling.


AutoMapper know how much?

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.