Views and Entity Framework

41,139

There's a great answer to that here: Entity Framework and SQL Server View (see accepted answer: https://stackoverflow.com/a/2715299/53510.)

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.

Share:
41,139
cepriego
Author by

cepriego

Updated on July 09, 2022

Comments

  • cepriego
    cepriego almost 2 years

    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.

    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.

    Any idea of how to solve this?

  • Erik Funkenbusch
    Erik Funkenbusch about 12 years
    If you use ISNULL or NULLIF, that makes the fields read-only, and thus the view becomes a read-only view for the most part. That's only useful in some situations