Entity Framework with Instead Of triggers

£可爱£侵袭症+ 提交于 2019-12-23 08:59:51

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!