user1180223
user1180223

Reputation: 111

DDD model to EF

I have two questions.

1: At the moment I have two model classes that are mapped to two entities in the EF diagram.

How does DDD work with EF because if I decide to split my model classes into smaller specific classes e.g. from 2 to 4. How will EF relate to them?

Will I have to create a seperate DTO to map these four model classes to the two entity models that EF will understand?

Just wondering how other people have managed to get around this issue.

2: EF only recognises models that have public properties. If I change my model class to have behavioural methods like GetName(), SetName(), GetAddress() etc and remove the public properties to be private members then EF throws a wobbly and complains it can not find any properties on my model. How do I solve this issue? Or would the answer be the same as the first question in that I need to create a DTO that has public properties which map from my model class which EF will use?

I'm just thinking if this is the correct path to take because it seems like a bit of redundant work having to map my DDD model classes to another set of DTO or EF model classes that EF understand. If I do have to map to the EF classes will they be in the model layer or repository layer?

Upvotes: 0

Views: 220

Answers (1)

Ladislav Mrnka
Ladislav Mrnka

Reputation: 364279

  1. There are possibilities to map multiple entities to the same table (TPH inheritance, table splitting) but these possibilities must follow strict rules. Otherwise you could end up with scenario where you cannot insert entity to database because it doesn't contain all required columns for the record.
  2. EF (with EDMX) recognizes non public properties as well - EF code fist requires at least property with accessible getter or setter. Moreover those behavioral methods can be redundant because writing your own getter and setter in property has the same meaning.

Upvotes: 1

Related Questions