我有实体:
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 映射 from PersonDetails
to PersonEntity
?