Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Views and Entity Framework

Tags:

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?

like image 702
cepriego Avatar asked Aug 05 '09 15:08

cepriego


People also ask

Does EF core support views?

From the perspective of EF Core, the database object specified in this method is a view, meaning that it is treated as a read-only query source and cannot be the target of update, insert or delete operations. However, this does not mean that the database object is actually required to be a database view.

How do I create a view in Entity Framework?

We can handle views in entity framework in two ways. Create a view combining multiple tables in the database manually and subsequently add an entity for the view. Finally, we can add ignore for the entity OnmodelCreating Entity builder, as shown below.

What is difference between Entity Framework and dapper?

Dapper is a lightweight tool that is developed by the StackOverflow developer team as a micro-ORM. On the other hand, Entity Framework is one of the most popular ORM tools among Dotnet developers. It is not a micro-ORM.


1 Answers

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.

like image 105
Greg Jackman Avatar answered Oct 18 '22 18:10

Greg Jackman