EF4独立的协会 - 为什么要避免呢? [英] EF4 Independent Associations - Why avoid them?

查看:110
本文介绍了EF4独立的协会 - 为什么要避免呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到MSDN(<此评论一href=\"http://social.msdn.microsoft.com/Forums/eu/adonetefx/thread/aed3b3f5-c150-4131-a686-1bf547a68804\"相对=nofollow>链接和<一个href=\"http://social.msdn.microsoft.com/Forums/eu/adonetefx/thread/3666f1a1-ff65-45bb-97dc-4c4013328eb1\"相对=nofollow>链接):

I saw this comment on MSDN (link and link):

需要注意的是独立的协会要经常因为像避免
  N层和并发性变得更加困难。

"Note that Independent Associations should often be avoided since things like N-Tier and concurrency becomes more difficult."

我是新来E​​F4和我建立一个n层的Web应用程序。这听起来像是一个重要的缺陷。能向我解释的人这是什么意思?

I'm new to EF4 and I'm building an n-Tier web app. This sounds like an important pitfall. Can someone explain to me what this means?

推荐答案

我认为这是个人的preference。最初,EF创建仅使用独立需求。协会和一个更经典的ERM的做法一致。然而,我们大多数开发者都如此依赖FKS,它使生活很复杂。因此,MS给了我们在EF4 FKS这意味着不仅具有FK作为依赖实体的属性,但关系是通过约束概念模型中定义,而不是埋在映射。仍然有一些关系,你只能用INDEP协会定义:多对多和独特的外键。请注意,如果您计划使用RIA服务(听起来并不像它)的RIA只承认FK关联。

I think it's personal preference. Originally, EF was created to only use indep. associations and aligned with a more classic ERM approach. However, most of us devs are so dependent on FKs that it made life very complex. So MS gave us FKs in EF4 which meant not only having the FK as a property in the dependent entity but the relationships are defined through constraints in the conceptual model rather than buried in the mappings. There are still a few relationships that you can only define with an indep association: many to many and unique foreign keys. Note that if you are planning to use RIA Services (doesn't sound like it) that RIA only recognizes FK associations.

所以,如果你preFER利用独立的协会仍然绝对可以在EF4使用它们。他们是完全支持。但正如詹姆斯指出,有几个陷阱要注意的,这样的东西你需要的,因为EF可与图表尤其是方式做更明确。或者你做到这一点的情况下想要的FK,例如,你有一个客户的ID,但你不等皆实例。你可以创建一个订单,但没有那该多好客户ID FK财产,你必须做一些额外的杂耍来获取客户ID在那里。

So if you prefer to leverage the independent associations you still absolutely can use them in EF4. They are totally supported. But as James suggests, there are a few more traps to be aware of...things that you'll need to do more explicitly because of the way EF works with graphs especially. Or that case where you do just want that FK , e.g., you have the ID of a customer but you don't h ave the instance. You could create an order but without that nice CustomerID FK property, you have to do some extra juggling to get that CustomerID in there.

心连心

这篇关于EF4独立的协会 - 为什么要避免呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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