2

有没有办法告诉 EF 在执行时不要更新单个表的 SSDL Update Model From Database

更多细节:
我们使用 EF 4.3 和 Db-first 方法(因此,edmx 和从数据库更新模型)。

我们有一个表,由于某些原因在 SQL Server 中没有设置主键,但有一个自动递增的Identity列,我们可以告诉 EF 将其用作主键。

由于 EF 没有在表本身中找到任何主键,因此它会在 SSDL 中为该表生成一个 DefiningQuery(并防止更新/插入)。

我可以轻松地删除该 DefiningQuery(并修改其他 EntitySet 属性)并且一切正常。

除非我再做一次Update Model From Database,DefiningQuery 又回来了。

有没有办法告诉 EF 不要为该单个表更新 SSDL?

4

1 回答 1

1

Is there a way to tell EF not to update SSDL for the single table when doing Update Model From Database?

Not with default designer provided in Visual Studio. Once you modify SSDL part of your EDMX file you should maintain it manually or write a script which will fix it every time you run Update from database.

Alternatively you can buy more powerful designer or extension to Visual Studio which will offer you selective update.

Anyway what you are trying to do should be avoided. If the database is owned by ERP you should do the access only through ERP programming API (real ERP has some). Otherwise you can break functionality of your ERP, corrupt ERP data, cause performance issues or even cause deadlocks.

于 2012-04-13T08:11:03.933 回答