0

I'm new to DDD but try to use the DDD ideas in my new project. I'm also using Entity Framework(edmx). On thing I've learnt about DDD is to avoid having public setters in the domain objects. If its correct, how do I map my EF entities(Ef generated classes) to my domain objects? Do I have to put all my initial values in the constructor?

Any help is appreciated!

Erik Z
  • 4,660
  • 6
  • 47
  • 74

1 Answers1

1

You don't need to have public setters in your entities when using EDMX file. You can change setter accessibility. After that you can use your EF entities as Domain entities and EF complex types as value objects. It still has some limitations so sometimes you will have to live with less ideal design to fit EF needs.

Community
  • 1
  • 1
Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
  • Thanks, but if I already have Domain entities and want to map EF entities to those? Maybe my question should have been: How do I map to domain entities with private setters? (regardless of the data-fetching-technic). – Erik Z Apr 18 '13 at 08:30
  • Private setters are still possible (but [the setter must exists](http://stackoverflow.com/questions/3574333/ef-4-0-mapping-to-readonly-property-with-private-field)) – Ladislav Mrnka Apr 18 '13 at 08:32
  • 1
    @Erik Z: you can access a private setter, or event a private readonly field via reflection. Alternatively, you can try to use constructor injection, if possible. Overall though, I'd try to void mapping between an EF mapped object and a domain object. Just map directly to the domain object. That way you get change tracking, etc. – eulerfx Apr 18 '13 at 15:55