使插入视图与EF6和SQLite一起使用

时间:2019-07-15 07:14:00

标签: entity-framework sqlite

我基于sqlite视图创建了一个实体,我想使用EF6在其中插入数据。我更改了.edmx文件,以使EF将视图视为表并在视图上定义主键。 问题是,当我的程序尝试向视图中插入数据时(当然,其中有一个INSTEAD OF INSERT触发器可以在视图的2个基础表上插入数据),我得到了异常:

  

存储更新,插入或删除语句影响了意外   行数(0)。自从以来,实体可能已被修改或删除   实体已加载。处理乐观并发异常。

从EF调用的基础查询是:

Opened connection at 12/07/2019 16:58:18 +02:00
Started transaction at 12/07/2019 16:58:18 +02:00
INSERT INTO [testcasesView]([name], [deviceversion_id], [user_id], [timestamp], [comment], [static_result], [description], [precondition], [action], [expected_result], [reviewed], [automated])
 VALUES (@p0, @p1, @p2, @p3, NULL, @p4, @p5, @p6, @p7, @p8, @p9, @p10);
SELECT [id]
FROM [testcasesView]
WHERE last_rows_affected() > 0 AND [id] = last_insert_rowid()
;
-- @p0: 'asd' (Type = String)
-- @p1: '67' (Type = Int64)
-- @p2: '20' (Type = Int64)
-- @p3: '1562943498' (Type = Int64)
-- @p4: 'as' (Type = String)
-- @p5: 'asd' (Type = String)
-- @p6: 'asd' (Type = String)
-- @p7: 'asd' (Type = String)
-- @p8: 'asd' (Type = String)
-- @p9: '0' (Type = Int64)
-- @p10: '0' (Type = Int64)
-- Executing at 12/07/2019 16:58:18 +02:00
-- Completed in 1 ms with result: SQLiteDataReader

Closed connection at 12/07/2019 16:58:18 +02:00
Disposed transaction at 12/07/2019 16:58:18 +02:00

我理解为什么,但是我不知道是否可以解决。问题在于,由于真正的插入发生在触发器内部(我不发布代码,因为它是两个简单的插入),因此查询

SELECT [id]
FROM [testcasesView]
WHERE last_rows_affected() > 0 AND [id] = last_insert_rowid()  

不返回任何内容,则EF认为没有行受到影响。

是否有可以添加到触发器中的语句或代码使EF看到插入发生了?

0 个答案:

没有答案
相关问题