We are trying to create an ASP.NET MVC 4 application using Entity Framework (EF) with domain-driven design (DDD) style pattern approach. As you can see in our part of domain layer, we have a complex design. We need to load an entity with lazy as well as eager methods. Unfortunately we have a big problem with these methods in Entity Framework.
As we understand, for eager loading in Entity Framework we have to use the Include
method and give string of properties and properties of properties, etc. (In Hibernate and Java we could use annotation top of member to load eagerly and it was so much easier than this approach).
But the horrible problem is that we have inheritance structures and heavy polymorphism. In these states we don’t have that’s string we should given to include, because we don’t know which derived class of a class is selected to understand which properties should be included.
For example, as you can see, a result has a collection of items and then decides to add some group to this collection and each of those groups have some groups and fields (like the composition pattern). Now imagine we want to load a result that is like the one talked above. When I want to write a string of a given include, I don’t know what items of this result are groups. Because we can’t predict these items are groups and so these groups have a collection of items which should load.
this.Items = new List<Item>
{
new Group(
a,
new List<Item>
{
new Field(b),
new Field(c),
new Field(d),
At last we have a critical question: is Entity Framework designed for Enterprise Applications with a complex domain and DDD approach? If not, how can we follow the approach of Martin Fowler and Eric Evans in software engineering and enterprise application in C#?