Automapper DTO到实体嵌套映射

时间:2012-07-25 13:56:29

标签: entity-framework automapper dto

我有实体:

public class Person
 {
   //properties
   public virtual State State { get; set; }
 }

 public class State
 {
       //properties
       public int StateId { get; set; }
       public string StateName { get; set; }
       public virtual Address Address{ get; set; }
 }

public class Address
 {
       //properties
       public int AddressId { get; set; }
       public string City{ get; set; }
       public int PostalCode { get; set; }       
 }

我有一个名为PersonDetails的展平DTO

public class PersonDetails
 {
       //properties
       public string City { get; set; }
       public string StateName { get; set; }
       public int PostalCode { get; set; }       
 }

当我进行映射时,它可以工作,但它会为Person实体创建一个新的State和Adress。

如何使用AutoMapper从PersonDetails映射到PersonEntity

0 个答案:

没有答案