Is it possible to insert a new row using a View with Linq to Entities?
I have a view on my database and I am trying to add a new record using the AddTo method but it is not working. I noticed that LinqToEntities is creating 开发者_开发知识库the insert statement like this
Insert into (select field1, field2 from my_view) (field1, field2) values (value1, value2)
Is it possible to make LinqToEntities create the insert statement like the one below ?
Insert into my_view (field1, field2) values (value1, value2)
Yes - this is a known issue with Views in Entity Framework.
Check out this MSDN blog for the workaround.
The key sentence from the blog:
ADO Entity Framework (EF) makes views Read Only via the
<DefiningQuery>
element. You make the data model view update-able by removing the element and making a few minor changes.
精彩评论