问题
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?
回答1:
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;
<EntitySet Name=".."
EntityType=".."
store:Type="Views"
store:Schema=".."
store:Name="..">
<DefiningQuery>SELECT ....</DefiningQuery>
You need to change this xml section in order to have CRUD operations;
<EntitySet Name=".."
EntityType=".."
store:Type="Tables"
Schema=".." />
来源:https://stackoverflow.com/questions/12217169/entity-framework-with-instead-of-triggers