I have to use a View with the EF but, when I import it, the primary key of the view is displayed incorrectly and for some reason I can't change it.
我必须使用带有EF的View,但是当我导入它时,视图的主键显示不正确,由于某种原因我无法更改它。
3 个解决方案
#1
Appears to be a known issue - see this other * question and its answers:
似乎是一个已知问题 - 请参阅此其他*问题及其答案:
Entity Framework and SQL Server View
实体框架和SQL Server视图
Marc
#2
I had a similar problem when i wanted to do a group by in a view that was not easy in linq but ended up not working. What worked for me was to specifically change the entity key in Entity Framework designer to a int column that is unique. If it doesnt exist then create a simple incremented int field in your view definition and use that as your key.
我有一个类似的问题,当我想在linq中不容易但最终无法工作的视图中进行分组时。对我有用的是专门将Entity Framework设计器中的实体键更改为唯一的int列。如果它不存在,那么在视图定义中创建一个简单的递增int字段,并将其用作您的键。
#3
In my experience the entity keys on a View are defined using the primary keys of the view (from the select clause). If you have multiple tables in the view you must select the primary key not the foreign key to see it as an entity key.
根据我的经验,View上的实体键是使用视图的主键(来自select子句)定义的。如果视图中有多个表,则必须选择主键而不是外键才能将其视为实体键。
Davide
#1
Appears to be a known issue - see this other * question and its answers:
似乎是一个已知问题 - 请参阅此其他*问题及其答案:
Entity Framework and SQL Server View
实体框架和SQL Server视图
Marc
#2
I had a similar problem when i wanted to do a group by in a view that was not easy in linq but ended up not working. What worked for me was to specifically change the entity key in Entity Framework designer to a int column that is unique. If it doesnt exist then create a simple incremented int field in your view definition and use that as your key.
我有一个类似的问题,当我想在linq中不容易但最终无法工作的视图中进行分组时。对我有用的是专门将Entity Framework设计器中的实体键更改为唯一的int列。如果它不存在,那么在视图定义中创建一个简单的递增int字段,并将其用作您的键。
#3
In my experience the entity keys on a View are defined using the primary keys of the view (from the select clause). If you have multiple tables in the view you must select the primary key not the foreign key to see it as an entity key.
根据我的经验,View上的实体键是使用视图的主键(来自select子句)定义的。如果视图中有多个表,则必须选择主键而不是外键才能将其视为实体键。
Davide