Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我必须将视图与 EF 一起使用,但是当我导入它时,视图的主键显示不正确,并且由于某种原因我无法更改它。
似乎是一个已知问题 - 请参阅其他 StackOverflow 问题及其答案:
实体框架和 SQL Server 视图
马克
当我想在 linq 中不容易但最终无法工作的视图中进行分组时,我遇到了类似的问题。对我有用的是专门将实体框架设计器中的实体键更改为唯一的 int 列。如果它不存在,则在您的视图定义中创建一个简单的递增 int 字段并将其用作您的键。
根据我的经验,视图上的实体键是使用视图的主键(来自 select 子句)定义的。
如果视图中有多个表,则必须选择主键,而不是外键,才能将其视为实体键。