带有实体框架4.0的复合数据库密钥 [英] Composite DB keys with Entity Framework 4.0

查看:77
本文介绍了带有实体框架4.0的复合数据库密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们公司对大型数据库的重新设计大量使用了数据库上的复合主键。

The re-design for a large database at our company makes extensive use of composite primary keys on the database.

忘记性能影响,这会在遇到问题时造成任何困难在Entity Framework 4.0中使用此数据库?数据库结构不太可能改变,我不是在寻找哲学上的争论,而是有什么实际影响?

Forgetting performance impacts, will this cause any difficulties when working with this db in Entity Framework 4.0? The database structure is unlikely to change and I'm not looking for "philosophical" debate but what are the practical impacts?

根据 Jeremy Miller ,组合键通常会使任何类型的对象/关系映射和持久性变得更加困难。但他并没有真正说出原因。

According to Jeremy Miller, "Composite key make any kind of Object/Relational mapping and persistance in general harder." but he doesn't really say why. Is this relavent to how Entity Framework 4.0 handles keys?

推荐答案

不,EF4支持复合键。

No, EF4 supports composite keys just fine.

问题是带有代理键和组合键的表。您只能在每个型号上设置一个键;该键可以有多个字段,但是从设计者的角度来看,您只能有一个字段。不确定手动编辑xml或仅编码映射。

The problem is a table with a surrogate key and composite keys. You can only set a single key on each model; that key can have multiple fields, but you can only have one from the designer standpoint. Not sure about manually editing xml or code only mapping.

如果需要在同一张表上使用复合键和替代键,则可以将字段设置为Identity而不是键。 Identity(ID)字段不会被ObjectContext或ObjectStateTracker使用,但是会递增并且可以查询。

You can set a field as an Identity and not a key if you need a composite and surrogate key on the same table. The Identity ( Id ) field won't be used by the ObjectContext or ObjectStateTracker but will increment and be queryable just fine though.

这篇关于带有实体框架4.0的复合数据库密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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