外键与独立关系 - 实体框架5有改进吗? [英] Foreign Key vs. Independent Relationships - is there improvement with Entity Framework 5?

查看:99
本文介绍了外键与独立关系 - 实体框架5有改进吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读几个文章和关于使用实体框架的外键概念与独立关系的问题
我仍​​然不能100%肯定哪个方式去....
我不想污染我的域POCOs有一个属性将被用于FK关系当我已经有我的问题是(看你@EFTeam,@Ladislav Mrnka)


  1. 在即将到来的Entity
    Framework v5中有关于此主题的任何改进?

  2. 如果使用FK而不是独立协会(特别是代码优先)?


解决方案

无论如何,必须污染您的域对象(或概念模型)。对于具有FK映射关联的模型,视图生成的成本 - 执行查询或保存更改所需的EF处理管道中的一个阶段,可以移动到构建时间(预生成视图) - 与具有独立协会的模型相比较低。这是很重要的,因为执行它的时间量对于小型模型可能是不明显的,但是它变得越来越快,特别是当将关联映射到可空的外键(到-0.1,或到-1时,派生实体在TPH映射层次结构中)。在官方 EF5性能注意事项文件一个非常大的模型的视图生成时间的示例差异在超过一个月,然后我们放弃(具有独立关联)和104分钟(具有FK映射关联)之间给出。在我的情况下(几百个高度连接的实体)它是在25分40秒之间。情况与EF5相同,与以前的版本相同。


I have read several articles and questions on concept of foreign key vs independent relationship when using Entity Framework. And I am still not 100% sure which way to go.... I would prefer not to "pollute" my domain POCOs by having a property that will be used in FK relationship when I already have a property reference to "has a" object.

My questions are (looking at you @EFTeam, @Ladislav Mrnka)

  1. are there any improvements on this subject in the upcoming Entity Framework v5?
  2. are there more advantages if I use FK instead of independent associations (particularly with code first)?

解决方案

If you have a large model, you're bound to "pollute" your domain objects (or conceptual model in general) anyway. For models with FK-mapped associations, the cost of "view generation" - a stage in the EF processing pipeline necessary to execute queries or save changes, one that can be moved to build-time ("pre-generating views") - is lower compared to models with independent associations. This is important because the amount of time to perform it may be unnoticeable for small models, but it gets longer very fast, especially when there are associations mapped to nullable foreign keys (to-0..1, or to-1 with derived entities in TPH mapped hierarchies). In the official EF5 performance considerations document an example difference in view generation time for a very large model is given as between "over a month and then we gave up" (with independent associations) and 104 minutes (with FK-mapped associations). In my case (several hundred highly connected entities) it's between 25 minutes and 40 seconds. The situation is the same in EF5 as it was in the previous versions.

这篇关于外键与独立关系 - 实体框架5有改进吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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