IMO you should not try to use your domain model objects as entity framework entities. You will not be able to craft properly encapsulated domain objects consisting of atomic methods. Instead they would need to have public properties with getters and setters that EF require, and this leads to an Anemic Domain Model.
Essentially: if you try to double up your domain objects as entity framework entities, you will compromise the design.
Instead, I employ the memento pattern, whereby I re-hydrate my domain objects with EF entities that serve as the mementos.
Given that EF can just use plain POCO's I'd put these classes in a different assembly to the assembly hosting your DbContext/Respositories, as your model will need to reference them. Because they are just POCO's you won't be tying your model to EF.
So you'd potentially have three assemblies:
- MyProject.Model ... which contains your DDD model classes
- MyProject.Data ... which contains DBContext and Repositories
- MyProject.Mementos ... which contains your EF POCO's
Example:
public class PersonRepository : EntityFrameworkRepository, IPersonRepository
{
public Person GetById(Guid personId)
{
using (MyDbContext ctx = new MyDbContext())
{
var personMemento = (from p in ctx.People
where p.PersonId == personId
select p).FirstOrDefault();
return Person.RestoreFromMemento(personMemento);
}
}
}