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

问题描述

大家好我们正在尝试在遗留数据库上使用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

推荐答案


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

08-20 20:44