Entity Framework instead of triggers

I am using EF with a SQL Server database. I created the Instead Of Insert view and trigger for this 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 displayed the view in EF edmx. When I try to add an object, I get the following exception when I call SaveChanges() :

Failed to update EntitySet TargetView because it has DefiningQuery and there is no item in it. item to support the current operation.

The view has an identity column marked in the mapping.

Any suggestions?

+7
source share
1 answer

If you open the EDMX file with the xml editor, in the section where TargetView is set, 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 modify this xml section to have CRUD operations;

 <EntitySet Name=".." EntityType=".." store:Type="Tables" Schema=".." /> 
+3
source

All Articles