视图和实体框架 [英] Views and Entity Framework
问题描述
我已经在数据库中创建了一个视图,希望将其包含在实体模型中。但是,当我尝试通过VS 2008更新实体模型时,出现一条警告消息,通知我我要添加的表或视图没有主键。
I've created a view in my database which I would like to include in my entity model. However, when I try to update the entity model through VS 2008, a warning message informs me that the TABLE OR VIEW I'm trying to add doesn't have a primary key.
似乎要向模型添加视图,必须有一个关键字段!如果不允许视图具有关键字段(至少在我正在使用的DBMRS的firebird中),如何将该视图添加到模型中。
It seems that in order to add a view to the model, this must have a key field! How can I add this view to my model if views are not permitted to have key field, at least in firebird which is the DBMRS I’m using.
任何想法
推荐答案
这里有一个很好的答案:实体框架和SQL Server视图(请参见已接受的答案: https://stackoverflow.com/a/2715299/53510 。)
There's a great answer to that here: Entity Framework and SQL Server View (see accepted answer: https://stackoverflow.com/a/2715299/53510.)
EF通过将所有非可为空的字段。您可以使用ISNULL和NULLIF来操纵视图列的可为空性,从而迫使EF选择所需的PK。
EF infers a PK for views by combining all non-nullable fields. You can use ISNULL and NULLIF to manipulate the nullability of view columns thereby forcing EF to pick the PK you want.
这篇关于视图和实体框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!