实体框架 4:如果数据库更新删除了排除的视图,如何将其映射到图表?
我收到此错误:
"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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是 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.