asp.net - Help Me Understand AutoMapper -
what point of automapper? give me simple example?
i have watched video on it, not clicking.
sam
typically automapper great @ mapping between data entities , business models. e.g., lets instance, have data domain type, call personentity
, , has array of properties: firstname
, surname
, gender
etc. don't want expose data domain type through consuming application, can define business domain types, e.g. person
, person
type can contain additional business logic, such getrelatedpersons
, etc, may not functionality tied data domain. in case, have 2 types, personentity
, person
@ point have write boilerplate code copy properties 1 other. variety of ways, could:
1.copy constructor:
public person(personentity entity) {
2.generalised mapping method:
public person createperson(personentity entity) {
3.implicit/explicit conversion:
public static implicit operator person(personentity entity) {
but automapper allows do, create mapping process between 2 types. in simiplist form, could:
person person = mapper.map<personentity, person>(entity);
by using convention-first approach, automapper framework translate matching properties 1 instance next. allows customise how types mapped if want more fine grained control.
hope helps.
Comments
Post a Comment