实体框架 4:如果数据库更新删除了排除的视图,如何将其映射到图表?

发布于 2024-10-10 23:13:50 字数 539 浏览 2 评论 0原文

我收到此错误:

"The table/view 'database.dbo.table' does not have a primary key defined and no
valid primary key could be inferred. This table/view has been excluded. To use 
the entity, you will need to review your schema, add the correct keys, and 
uncomment it."

因此,我取消了它的注释,添加了 EntityKeys、EntityTypes 和查询。一切工作正常,直到我“从数据库更新模型”,这删除了我的所有更改。

如何让实体框架识别“从数据库更新模型”下的视图?是否可以向 Microsoft SQL 2005 视图添加任何内容,以便 EF 可以作为主键字段?

我的视图只有两个字段:

ID int not null, -- PK
SKU int null

I got this error:

"The table/view 'database.dbo.table' does not have a primary key defined and no
valid primary key could be inferred. This table/view has been excluded. To use 
the entity, you will need to review your schema, add the correct keys, and 
uncomment it."

So, I un-commented it, added EntityKeys, EntityTypes, and a query. Everything worked fine, until I "Update Model From Database", which erased all my changes.

How can you get Entity Framework to recognize the view under the "Update Model From Database"? Is there anything you can add to the Microsoft SQL 2005 view so that EF could pickup as the primary key fields?

My view only has two fields:

ID int not null, -- PK
SKU int null

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

能否归途做我良人 2024-10-17 23:13:50

这是 EF 设计器的已知限制。模型的存储部分由“从数据库更新模型”向导重新生成,这就是问题的原因。

此问题已在 Devart Entity Framework 支持论坛此处进行了讨论。

This is a known EF Designer limitation. The Store part of the model is regenerated by the Update Model From Database wizard, this is the reason of the problem.
This problem was already discussed at the Devart Entity Framework Support forum here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文