Entity Framework with Instead Of triggers

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;

<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=".." />
链接地址: http://www.djcxy.com/p/11140.html

上一篇: 逆向工程?

下一篇: 使用实体框架而不是触发器