具有现有域模型的实体框架 4
我目前正在考虑从 Fluent nHibernate 迁移到 ADO.Net Entity Framework 4。
我有一个包含用于 nHibernate 映射的域模型 (pocos) 的项目。我在博客中读到,可以将我现有的域模型与 EF4 一起使用,但我没有看到任何示例。我见过使用 EF4 生成 T4 代码的示例,但还没有遇到显示如何将现有域模型对象与 EF4 结合使用的示例。我是 EF4 的新手,希望查看一些有关如何完成此操作的示例。
谢谢 艾亚兹
Im currently looking at migrating from fluent nHibernate to ADO.Net Entity Framework 4.
I have a project containing the domain model (pocos) which I was using for nHibernate mappings. Ive read in blogs that it is possible to use my existing domain model with EF4 but ive seen no examples of it. Ive seen examples of T4 code generation with EF4 but havent come accross an example which shows how to use existing domain model objects with EF4. Im a newby with EF4 and would like to see some samples on how to get this done.
Thanks
Aiyaz
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
快速演练:
ObjectContext
继承的类以公开实体(通常与 .edmx 文件位于同一项目中)ObjectSet
类型的属性示例代码:
就是这样...
重要通知: 如果您使用自动创建代理以进行更改跟踪(
ContextOptions.ProxyCreationEnabled
,默认情况下为 true),域类的属性必须是 virtual。这是必要的,因为 EF 4.0 生成的代理将覆盖它们以实现更改跟踪。如果您不想使用自动代理创建,则需要自己处理更改跟踪。有关详细信息,请参阅此 MSDN 页面
Quick walkthrough :
ObjectContext
to expose the entities (typically in the same project as the .edmx file)ObjectSet<TEntity>
for each of you entitiesSample code :
That's about it...
Important notice : if you use the automatic proxy creation for change tracking (
ContextOptions.ProxyCreationEnabled
, which is true by default), the properties of your domain classes must be virtual. This is necessary because the proxies generated by EF 4.0 will override them to implement change tracking.If you don't want to use automatic proxy creation, you will need to handle change tracking yourself. See this MSDN page for details