Reputation: 3896
I have domain model and data model:
I would like to map DoM <> DaM in both directions. I have tried Automapper, but I am having one big issue with it, say DaM data model has an entity Car, which is a direct translation of the database table
Car
{
Type {get; set;}
MaxSpeed {get; set;}
}
Domain model DoM has the following structure:
Car
{
MaxSpeed {get; set;}
}
SportsCar : Car
{
}
F1 : SportsCar
{
}
And the mapping should be:
if (DaM.Car(car).Type == Type.SportsCar)
DaM.Car.MaxSpeed > 350 ? map DaM.car to DoM.F1 : map DaM.car to DoM.SportsCar
What is the best way/tool to archive that?
How I can do it with automapper or valueinject?
Upvotes: 1
Views: 343
Reputation: 71288
valueinjecter by default will match all properties of same name and type from source to target regardless of types so it would be something like this:
a.InjectFrom(b);
note a and b already exist, you create them in advance
you can see valueinjecter being used with EF in mvc project here: http://prodinner.codeplex.com
Upvotes: 1
Reputation: 466
Have you looked into Table Per Hierarchy mappings using Entity Framework? Using the Type property on Car as the discriminator, you'd be able to add SportsCar and F1 entities to the data model and Entity Framework would retrieve them direct from the database. You could then use AutoMapper if you really want to have separate SportsCar and F1 classes in your domain model.
Upvotes: 2