与INSTEAD OF触发器实体框架 [英] Entity Framework with Instead Of triggers
本文介绍了与INSTEAD OF触发器实体框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用EF与SQL Server数据库。我创建了一个视图和而不是插入
触发该视图看起来像这样:
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()
我映射视图到EF EDMX。当我尝试添加一个实体出现以下异常,当我打电话的SaveChanges()
:
的无法更新EntitySet的'的TargetView,因为它有一个DefiningQuery并没有元素在
元素的存在是为了支持目前的
操作。的
该视图标志着映射标识列。
The view has an identity column marked in the mapping.
有什么建议?
推荐答案
如果你打开EDMX文件,XML编辑器,在的TargetView定义你将有类似于以下一些XML部分;
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>
您需要更改此XML部分才能有CRUD操作;
You need to change this xml section in order to have CRUD operations;
<EntitySet Name=".."
EntityType=".."
store:Type="Tables"
Schema=".." />
这篇关于与INSTEAD OF触发器实体框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文