Should foreign Id properties be mapped from Model to Dto?

automapper c# entity-framework graphdiff

Question

If I have the model shown below:

public class Customer
{
    public int Id {get; set;}
    public int CustomerTypeId {get; set;}
    public virtual CustomerType {get; set;}
}

Should foreign IDs be excluded to look like this:

public class CustomerDto
{
    public int Id {get; set;}
    public virtual CustomerType {get; set;}
}

And will EF be able to recognize that CustomerType maps to CustomerTypeId when updating the object graph using Graphdiff?

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

Popular Answer

Yes, you must utilize it, but you don't have to declare a virtual member. If you employAutoMapper subsequently, the mapping will be carried out automatically. Thus, your Dto will seem as follows:

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

The mapping is also

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