4
votes

I wonder how could I obtain an automatic mapping between entities generated by entity framework (.NET Framework 3.5 SP1) and custom domain model classes? I know I can create some data converters that translates the objects back and forth between the two worlds, but how could I accomplish this in an automatic way?

I started to develop my domain model classes, decorating them with validation attributes from Validation application block, which cannot be used inside the entity classes automatically generated (and refreshed) by the entity framework. Hence the need for automatically - or at least with minimal written code - mapping between EF and domain model.. any idea?

2
Were you able to accomplish this in EFv4? I would liek to do the same thing and I was wondering how you did it...if you got it to work.Dan H

2 Answers

2
votes

In EF 1.0, Automapper is a good choice for this: http://www.codeplex.com/AutoMapper

1
votes

With EF 4 this is now possible, You should have a look at Julie Lermann blog about EF . She recently made a whole series of post about POCO scenario and repositories with EF4 :

http://thedatafarm.com/blog/

With EF 3.5 this is hard, but you could still use Automapper if your class have the same set of attributes...

http://automapper.codeplex.com/