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?
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With