我无法将实体插入映射视图。我得到的错误是:
[存储,插入或删除语句影响了意外的行数(0)
我知道如何使用存储过程,但是对我来说,尝试在插入行视图事件中使用触发器而不是触发器的解决方案更有趣。删除,更新或插入t-sql代码时没有出现任何错误,但是我无法使用EF插入行。更新和删除EF中的工作,但不插入。
代码:
create view TestInsert
as
select a.table_id, a.name
from TableA as a
create trigger tr_works_via_tsql_but_not_ef_for_some_reason
on TestInsert
instead of isert
begin
insert into TableA (table_id, name)
select table_id, name from inserted;
end
[Table(TestInsert)]
public class TestInsert
{
[Key]
public int table_id { get; set; }
public string name { get; set; }
}
有人可以帮我吗?
[万岁,我已经找到解决方法!正文而不是触发器必须返回表的ID。
create trigger tr_works_via_tsql_but_not_ef_for_some_reason
on TestInsert
instead of isert
begin
insert into TableA (table_id, name)
select table_id, name from inserted;
**select id from TableA where @@ROWCOUNT > 0 and id = scope_identity()**
end
我使用直接映射,并且我的项目中没有edmx文件。这是答案的来源:Entity Framework with Instead Of triggers