DDD与EF code首先 - 如何把它们放在一起? [英] DDD with EF Code First - how to put them together?

查看:266
本文介绍了DDD与EF code首先 - 如何把它们放在一起?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我学习DDD开发几天,我开始喜欢它。

I am learning DDD development for few days, and i start to like it.

我(我想)知道DDD,你的主要重点是业务对象,那就是你有聚集的原则,聚合根,仓库只为聚集的根等等。

I (think i) understand the principle of DDD, where your main focus is on business objects, where you have aggregates, aggregates roots, repositories just for aggregates roots and so on.

我想创建一个简单的项目,我结合DDD开发code第一种方法。

I am trying to create a simple project where i combine DDD development with Code First approach.

我的问题是:(我使用asp.net MVC)

My questions are: (I am using asp.net MVC)


  1. DDD Business Objects公司将超过code首先对象有什么不同?
    即使他们可能是相同的,比如我可以有一个产品业务对象里面有所有的规则和方法,我可以有一个产品 code第(POCO)对象将只包含我需要在数据库中保存属性。

  1. DDD Business Objects will be different than Code First objects? Even if they will probably be the same, for example i can have a Product business object which has all the rules and methods, and i can have a Product code first (POCO) object which will just contain the properties i need to save in database.

如果问题1的答案是真,那么我怎么通知产品 POCO对象,从业务对象的属性产品已经改变了,我必须更新吗?我使用的是AutoMapper或者类似的东西呢?
如果答案是不,我完全失去了。

If answer to question 1 is "true", then how do i notify the Product POCO object that a property from business object Product has been changed and i have to update it? I am using an "AutoMapper" or something like this? If the answer is "no", i am completely lost.

你能告诉我,我怎么可以把那两个在一起最简单的(CRUD)的例子?

Can you show me the most simple (CRUD) example of how can i put those two together?

感谢您

推荐答案

答案是约EF code-第一最好的事情之一是号,它与DDD非常适合,因为你必须创建你的业务对象用手所以一定要使用你的EF模型相当于DDD实体和值对象。无需添加复杂额外的一层,我不认为DDD建议的任何地方。

The answer is No. One of the best things about EF code-first is that it fits nicely with DDD since you have to create your business objects by hand so do use your EF models to be equivalent to DDD entities and value objects. No need to add an extra layer of complexity, I don't think DDD recommends that anywhere.

您甚至可以有你的实体实施IEntity和你的价值对象来实现IValue,还遵循DDD模式其余库就是做数据库的实际沟通。更多的这些想法,你可以找到在.net中,此很好的示例应用程序,即使它不首先使用EF code,它仍然是非常有价值的:的 HTTP://$c$c.google.com/p/ndddsample/

You could even have your entities to implement an IEntity and you value objects to implement IValue, additionally follow the rest of DDD patterns namely Repositories to do the actual communication to the database. More of these ideas you can find this very good sample application in .NET, even though it doesn't use EF code first, it's still very valuable: http://code.google.com/p/ndddsample/

这篇关于DDD与EF code首先 - 如何把它们放在一起?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆