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

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

问题描述

我已阅读几个文章, 问题上使用实体框架时,外键VS独立的关系的概念。
和我仍然不是100%肯定去....
我宁愿不要污染我的域名通过波苏斯具有将在FK关系中使用时,我已经有一个属性,它的方法一个属性提到有的对象。



我的问题是(看你@EFTeam,@Ladislav Mrnka)




  1. 有没有关于这个问题在即将到来的实体
    框架V5?

  2. 的任何改进
  3. 是,如果我使用有更多的优势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.

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

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