Updatable Views in Entity Framework 5/6

c# entity-framework-5 entity-framework-6


I have several Views that are updatable according to http://technet.microsoft.com/en-us/library/ms187956.aspx.

All of my views follow the specifications in the afformentioned article. I have verified in SQL Management Studio that the views can be updated, inserted to, and deleted from.

The research I have done has led me to two options to make the views in my Entity Framework 5/6 Model updatable:

  1. Remove the tag from each view, however, any work done in MyContext.edmx is overwritten when updating the context from the database. This means that this solution isn't very viable for my project.

  2. Adding a insert, update, and delete stored procedure for each view and mapping these in the designer. I don't particularly like the idea of having to create this many stored procedures.

Is there any easy way to tell EF5 OR EF6 that the views can be added to/updated/deleted from that will not be wiped out when running subsequent "Update Model from Database" commands without writing stored procedures for each entry method(insert, update, delete) on each view?

8/27/2015 2:41:29 PM

Popular Answer

I would think that your easiest method, would be to change the definition of your EntitySet in your StorageModel to tell it to regard it as a table, as opposed to a database-view.

Looking at the XML definition, where it says

<EntitySet Name="Products" store:Type="Views" ..

you change that to

<EntitySet Name="Products" store:Type="Tables" ..

(Note the "Products" is just an example) This should be in your .edmx file.
See pg 44, Lerman, "Programming Entity Framework", 2nd Ed.

Hope this helps.

4/14/2014 1:32:09 AM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow