1

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.

Vaccano
  • 78,325
  • 149
  • 468
  • 850

3 Answers3

1

Assuming that your contract class doesn't have the association properties, you could use this extension method to ignore them all in one statement:

Mapper.CreateMap<MyContractClass, MyDalClass>().IgnoreAllNonExisting();
Community
  • 1
  • 1
jrummell
  • 42,637
  • 17
  • 112
  • 171
0

You can use EntitiesToDTOs which is simpler than AutoMapper. You don't have to write the map, neither configurate it. It is all automatically generated by the tool.

kzfabi
  • 2,065
  • 1
  • 22
  • 26
0

I'm using T4 templates to generate the mappings from the EDMX model. This works very well and has saved me a lot of time so far. The idea is from this guy. You can download his templates and customize them to work for your scenario.

Andreas
  • 6,447
  • 2
  • 34
  • 46