[英]Should foreign Id properties be mapped from Model to Dto?
If I have the following model: 如果我有以下模型:
public class Customer
{
public int Id {get; set;}
public int CustomerTypeId {get; set;}
public virtual CustomerType {get; set;}
}
Should the Dto exclude foreign Id's to look like this: Dto是否应排除外籍ID如下所示:
public class CustomerDto
{
public int Id {get; set;}
public virtual CustomerType {get; set;}
}
And when using Graphdiff to update the object graph, will EF know that CustomerType maps to CustomerTypeId? 当使用Graphdiff更新对象图时,EF是否会知道CustomerType映射到CustomerTypeId?
Yes, you need to use it but you can avoid virtual member declaration. 是的,您需要使用它,但是可以避免虚拟成员声明。 If you use
AutoMapper
, then the mapping will be done automatically. 如果使用
AutoMapper
,则映射将自动完成。 So, your Dto will look like this: 因此,您的Dto将如下所示:
public class CustomerDto
{
public int Id {get; set;}
public int CustomerTypeId {get; set;}
}
And the mapping: 和映射:
Mapper.CreateMap<Customer, CustomerDto>();
Mapper.CreateMap<CustomerDto, Customer>();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.