Adding a logical key to a View in SQL Server Manager

╄→尐↘猪︶ㄣ 提交于 2019-12-24 18:37:52

问题


The .NET Entity framework is giving me the following error:

"The table/view 'Foo.dbo.vwFoo' 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."

The view is a collection of a variety of tables and calculations. What I'd like to do is create a "logical key" using one of the columns that I know should be unique. I can't figure out how to do this in SQL Server Manager 2005 (not a DBA.)

Anyone know how I could accomplish this?


回答1:


The EF can't find the PK, because VIEWs don't have PKs. However, if the view returns a unique column, you can tell the EF that this is the "PK."

It's explained in this tip: How to work with Updatable Views



来源:https://stackoverflow.com/questions/1368964/adding-a-logical-key-to-a-view-in-sql-server-manager

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!