Entity framework and Eager loading and enterprise application with DDD aproach

北慕城南 提交于 2020-01-05 05:44:06

问题


ITNOA

We are trying to create an ASP.NET MVC 4 application using entity framework with domain driven development style pattern approach. As you can see in our part of domain layer, we have a complex design. We need to load entity with lazy as well as eager methods. Unfortunately we have big problem with these methods in entity framework.

As we understand, for eager loading in EF 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 class is selected to understand which properties should include.

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 is like the one talked above. When I want to write a string of 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 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 we follow the approach of Martin Fowler and Eric Evans in software engineering and enterprise application in C#?


回答1:


is entity framework designed for Enterprise Applications with a complex domain and DDD approach?

Yes.

A real domain model may differ in shape from the corresponding data model for many reasons. The goal of an "enterprise" ORM like EF or NHibernate is to translate between the two, even to the point of supporting multiple databases.

What I don't really see is your domain model. Your diagram looks like a data model, which is an implementation detail. I'd expect to see Doctor, Patient, Questionnaire, Appointment, Treatment, Prescription etc. You may choose to store these in the style you describe (StackOverflow stores both questions and answers as "Posts", for example) but that's what the mapping is for, and to be honest if you're using a relational database you might be better off having tables that are similar to the domain model. If you're going for a totally flexible storage then an RDBMS is probably not the right tool - consider perhaps a document database instead?



来源:https://stackoverflow.com/questions/19983814/entity-framework-and-eager-loading-and-enterprise-application-with-ddd-aproach

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!