[英]Should foreign Id properties be mapped from Model to Dto?
如果我有以下模型:
public class Customer
{
public int Id {get; set;}
public int CustomerTypeId {get; set;}
public virtual CustomerType {get; set;}
}
Dto是否應排除外籍ID如下所示:
public class CustomerDto
{
public int Id {get; set;}
public virtual CustomerType {get; set;}
}
當使用Graphdiff更新對象圖時,EF是否會知道CustomerType映射到CustomerTypeId?
是的,您需要使用它,但是可以避免虛擬成員聲明。 如果使用AutoMapper
,則映射將自動完成。 因此,您的Dto將如下所示:
public class CustomerDto
{
public int Id {get; set;}
public int CustomerTypeId {get; set;}
}
和映射:
Mapper.CreateMap<Customer, CustomerDto>();
Mapper.CreateMap<CustomerDto, Customer>();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.