Should foreign Id properties be mapped from Model to Dto?

automapper c# entity-framework graphdiff

Question

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:

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?

1
0
2/4/2015 9:57:53 AM

Popular Answer

Yes, you need to use it but you can avoid virtual member declaration. If you use AutoMapper, then the mapping will be done automatically. So, your Dto will look like this:

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

And the mapping:

Mapper.CreateMap<Customer, CustomerDto>();
Mapper.CreateMap<CustomerDto, Customer>();
0
2/4/2015 4:39:09 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow