0

如果我有以下型号:

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 吗?

4

1 回答 1

0

是的,您需要使用它,但您可以避免虚拟成员声明。如果使用AutoMapper,则映射将自动完成。因此,您的 Dto 将如下所示:

public class CustomerDto
{
    public int Id {get; set;}
    public int CustomerTypeId {get; set;}
}

和映射:

Mapper.CreateMap<Customer, CustomerDto>();
Mapper.CreateMap<CustomerDto, Customer>();
于 2015-02-04T16:39:09.167 回答