I am using EF with a SQL Server database. I created a view and an Instead Of Insert trigger for that view which looks like this:
insert into Target (value, someFk)
select value, 4 from inserted
select id from Target where @@ROWCOUNT > 0 and id = scope_identity()
I mapped the view into an EF edmx. When I try to add an entity I get the following exception when I call SaveChanges():
Unable to update the EntitySet ‘TargetView’ because it has a DefiningQuery and no element exists in the
element to support the current
operation.
The view has an identity column marked in the mapping.
Any suggestions?
If you open EDMX file with an xml editor, in the section where TargetView is defined you will have some xml similar to the following;
You need to change this xml section in order to have CRUD operations;