[英]Entity Framework with Instead Of triggers
我使用EF與SQL Server數據庫。 我為該視圖創建了一個視圖和一個Instead Of Insert
觸發器,如下所示:
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,並且元素中不存在支持當前操作的元素。
視圖在映射中標記了標識列。
有什么建議么?
如果使用xml編輯器打開EDMX文件,則在定義TargetView的部分中,您將獲得類似於以下內容的xml;
<EntitySet Name=".."
EntityType=".."
store:Type="Views"
store:Schema=".."
store:Name="..">
<DefiningQuery>SELECT ....</DefiningQuery>
您需要更改此xml部分才能進行CRUD操作;
<EntitySet Name=".."
EntityType=".."
store:Type="Tables"
Schema=".." />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.