非身份主键策略 [英] Non Identity Primary Key Strategy

查看:70
本文介绍了非身份主键策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好我们正在尝试在遗留数据库上使用VS2010实施EF 4.0,遗憾的是,不使用表主键的标识字段(PK列是当前系统使用自定义的INT服务器端代码获取maxID然后递增1以创建新的主键 - 可怕的数据库设计是,但我们坚持使用它。)
。寻找有关如何使用EF实现此目的的最佳实现的想法。在我的EDMX模型中,我尝试更改PK字段的属性以使Setter变为私有(意图以某种方式在调用context.Savechanges()时生成PK值)但是到目前为止实际代码是如何不知所措在实践中这一点。

有关如何最好地实现这一点的任何想法或建议?

感谢


asdf

Hi all

We are trying to implement EF 4.0 with VS2010 on a legacy database which unfortunately does not use Identity fields for table primary keys (the PK columns are however INTs which the current system uses custom server side code to get a maxID then increment by 1 to create a new primary key - dreadful DB design yes but we are stuck with it).

Looking for ideas on how best to implement this using EF.  In my EDMX model I have tried changing the properties of the PK fields to make the Setter private (with the intention of somehow generating the PK value when context.Savechanges() is called) but thus far am at a loss as to how actually code this up in practice.

Any ideas or suggestions as to how best to accomplish this ?

Thanks


asdf

推荐答案

您好asdf,

由于您正在使用EF 4.0,我正在将此主题移至EF预发布论坛。
还有更多专家关于EF 4.0问题。

最诚挚的问候是,刘正春
Hi asdf,

Since you are working with EF 4.0, I'm moving this thread to EF pre-release forum.
There are more experts on EF 4.0 issues.

Best Regards
Yichun Feng


这篇关于非身份主键策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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