ADO.NET DbContext 生成器与 ADO.NET Poco 实体生成器 (ObjectContext)
我即将开始实现一个采用 DDD 方法构建的项目的数据访问基础设施(这是我第一次尝试 DDD,所以要温和;-))。
我将使用实体框架。到目前为止,我一直在研究 Julie Lerman 在她的伟大著作 编程实体框架中教授的方法,其中使用 ADO.NET POCO 实体生成器,对 T4 模板进行了一些更改,并添加了一些自定义代码。
今天,我开始阅读有关 EF4.1 和 ADO.NET DbContext Generator 的文章,使用数据库优先方法,我正在考虑选择哪一个。
DbContext 和 EF4.1 在 DDD 上的方法似乎是比 POCO Entities 更好、更干净的方法,但我担心它可能会在不久的将来导致一些问题,因为 EF4.1 仍处于 RC 状态。
来自 ADO。 NET 团队博客,我知道 EF4.1 不包括:
- 枚举支持
- 空间数据类型支持
- Code First 中的存储过程支持 Code First 中的
- 迁移支持
- Code First 中的可自定义约定
据我了解,由于我将使用数据库优先,因此未包含少量功能。
总之,我的问题是:
我可以用 EF4.1 DbContext 生成器替换POCO 实体生成器吗?
I am about to start implementing the data access infrastructure of a project that was architected with an approach to DDD (it's my first attempt on DDD, so be gentle ;-) ).
I will be using Entity Framework. Until now, I was looking into the method teached by Julie Lerman on her great book, Programming Entity Framework, where ADO.NET POCO Entity Generator is used, with some changes to the T4 templates and some more custom code.
Today I started reading articles on EF4.1 and the ADO.NET DbContext Generator, using Database First approach, and I'm trying to decide with which one should I go.
DbContext and EF4.1's approach on DDD seems to be a nice, cleaner way than POCO Entities, but I'm afraid that it could lead to some issues in the near future, since EF4.1 is still in RC.
From ADO.NET team blog, I know that EF4.1 does not include:
- Enum support
- Spatial data type support
- Stored Procedure support in Code First
- Migration support in Code First
- Customizable conventions in Code First
From my understanding, since I will be using Database First there is a smaller number of features that were not included.
In conclusion, my question is:
Can I replace POCO Entities Generator with EF4.1 DbContext Generator?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从 POCO 实体的干净创建的角度来看,两个生成器之间没有区别。两个生成器生成相同的实体,但是,ADO.NET POCO 实体生成器基于
ObjectContext
的 API,而 ADO.NETDbContext
生成器基于DbContext
的 API。DbContext 的 API 有一些非常好的新功能(本地、导航属性查询等),并且 API 在某种程度上得到了简化,但同时看起来 DbContext API 中缺少 ObjectContext API 中使用的一些功能(或者至少它具有还没有被充分探索)。
EF 4.1 RC 已上线。这意味着您可以用它构建一个真正的应用程序,因为 API 在 RTW 中不会改变(只会修复错误)。 RTW 应该在下个月发布,所以我认为在最终版本发布之前您还没有准备好您的应用程序。
ObjectContext
API 还是DbContext
API?文档和博客文章更好地介绍了ObjectContext
API。你可以找到很多关于它的例子。它的局限性也是众所周知的。DbContext
API 是新版本。这是一个非常有前途的版本,主要是因为代码优先的方法。博客文章的数量仍然非常有限,没有书籍,API 也没有得到足够的验证。所以这取决于你是否准备好迎接新的 API 了?如果没有,那么ObjectContext
API 仍然是一个不错的选择,因为您不需要代码优先的方法。From a point of view of clean creation of POCO entities, there is no difference between the two generators. Both generators produce the same entities, however, ADO.NET POCO Entity Generator is based on
ObjectContext
's API, whereas ADO.NETDbContext
Generator is based onDbContext
's API.DbContext's API has a few very nice new features (Local, Query on navigation property, etc.) and API is somehow simplified but at the same time it looks like some features used in ObjectContext API are missing in DbContext API (or at least it has not been explored enough yet).
EF 4.1 RC is go-live release. It means that you can build a real application with it because API will not change in RTW (only bugs will be fixed). Also RTW should be in the next month so I think you will not be ready with your application before the final version is shipped.
ObjectContext
API orDbContext
API?ObjectContext
API is much better covered by documentation and blog posts. You can find plenty of examples about it. Also its limitations are already well known.DbContext
API is new release. A very promising release, mostly because of the code-first approach. There is still a very limited number of blog posts, no book and the API is not proven enough. So it depends if you are ready to fight with new API? If not, thenObjectContext
API is still a good choice because you don't need the code-first approach.