本文介绍了在SQL Server管理器中为View添加逻辑键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.NET实体框架给我以下错误:



表/视图Foo.dbo.vwFoo没有定义主键,没有有效的主键可以被推断,这个表/视图被排除在外,为了使用实体,你需要查看你的模式,添加正确的键并取消注释。



该视图是各种表和计算的集合。我想做的是创建一个逻辑键,使用我知道的一个列应该是唯一的。我不知道如何在SQL Server Manager 2005(而不是DBA)中执行此操作。



任何人都知道如何才能完成此操作?

解决方案

EF找不到PK,因为VIEW没有PK。但是,如果视图返回一个唯一的列,您可以告诉EF这是PK。



在此提示中解释:


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?

解决方案

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

这篇关于在SQL Server管理器中为View添加逻辑键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 01:47