I am mapping quite a few WCF Data Contracts to Entity Framework Classes.
For every class I have to do this kind of thing:
Mapper.CreateMap<MyContractClass, MyDalClass>()
.ForMember(x => x.EntityKey, opt => opt.Ignore())
.ForMember(x => x.SomeAssociation, opt => opt.Ignore())
.ForMember(x => x.SomeAssociationReference, opt=> opt.Ignore())
// Repeat
// the
// last
// /two
// lines
// for
// every
// single
// association
// (Some classes have a lot of associations)
;
Is there an easier way? Some way to rule out all the extra stuff put in by EntityFramework?
Or does this just have to be done by hand?
NOTE: I have extensively evaluated the POCO template and it does not work for my scenario. Please do not just recommend that instead of Automapper.
Assuming that your contract class doesn’t have the association properties, you could use this extension method to ignore them all in one statement: