简体   繁体   English

域驱动设计,.NET和实体框架

[英]Domain Driven Design, .NET and the Entity Framework

I'm new to domain driven design but want to learn it and use it for a new application. 我是域驱动设计的新手,但想学习它并将其用于新的应用程序。 I will be using Entity Framework for data access. 我将使用Entity Framework进行数据访问。

The basic layout so far is: 到目前为止的基本布局是:

ASP.NET MVC and other clients (mobile devices etc.) ASP.NET MVC和其他客户端(移动设备等)
| |
Webservices 网页服务
| |
Domain Model (Services, Repositories, Aggregates, Entities and Value Objects) 域模型(服务,存储库,聚合,实体和值对象)
| |
Data Access Layer (Entity Framework) 数据访问层(实体框架)
| |
Data Storage (SQL Server) 数据存储(SQL Server)

What is the best way to transfer data between the data access layer and the domain model? 在数据访问层和域模型之间传输数据的最佳方法是什么? I'm thinking that the entities in the domain model are POCO objects and that they should be mapped to/from the Entity Framework objects. 我认为域模型中的实体是POCO对象,它们应该映射到Entity Framework对象/从Entity Framework对象映射。 Is this a good solution? 这是一个好的解决方案吗?

If so: 如果是这样的话:
How and where should such a mapping occur? 这种映射应该如何以及在何处发生? (Domain Model Layer or Data Access Layer) (域模型层或数据访问层)
Where and how should I query Entity Framework (ie. return a list based on a search)? 我应该在哪里以及如何查询实体框架(即根据搜索返回列表)?

ANDREY YEMELYANOV has done a masters thesis on this exact subject: ANDREY YEMELYANOV就这个确切的主题做了一个硕士论文:

http://gupea.ub.gu.se/dspace/bitstream/2077/10462/1/gupea_2077_10462_1.pdf http://gupea.ub.gu.se/dspace/bitstream/2077/10462/1/gupea_2077_10462_1.pdf

This will get much easier with the release of EF 4, which supports POCO objects. 随着支持POCO对象的EF 4的发布,这将变得更加容易。

In the meantime you could try using automapper to map between domain and EF objects, see: http://www.lostechies.com/blogs/jimmy_bogard/archive/2009/01/22/automapper-the-object-object-mapper.aspx 在此期间,您可以尝试使用automapper在域和EF对象之间进行映射,请参阅: http//www.lostechies.com/blogs/jimmy_bogard/archive/2009/01/22/automapper-the-object-object-mapper。 ASPX

I'm thinking that the entities in the domain model are POCO objects and that they should be mapped to/from the Entity Framework objects. 我认为域模型中的实体是POCO对象,它们应该映射到Entity Framework对象/从Entity Framework对象映射。 Is this a good solution? 这是一个好的解决方案吗?

I think it is. 我觉得是这样的。

This is something that we have done quite successfully, although in my case in the Java world. 这是我们已经非常成功的事情,尽管在我的Java世界中。 Our domain classes contain the majority of the business logic. 我们的域类包含大多数业务逻辑。 Each has a reference to a thin data entity object and delegates the getting and setting of the persistent properties to the data entity. 每个都有一个对瘦数据实体对象的引用,并将持久属性的获取和设置委托给数据实体。

I would go for Enterprise Core Objects (ECO) from capableobjects.com 我会从ableobjects.com上购买Enterprise Core Objects(ECO)

It does everything you would ever want from a DDD framework 它可以完成您从DDD框架中获得的所有功能

The S#arp architecture project is an excellent starting point for guidance on applying DDD. S#arp架构项目是应用DDD指南的绝佳起点。 It is based on NHibernate, but the principles used should hold equally for EF... 它基于NHibernate,但所使用的原则应该同样适用于EF ......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM