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.

3 Answers 3

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();
Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.