我正在将我的应用程序转换为.NET Core。这样,我遇到了EF Core和插入的问题。
I am converting my application to .NET Core. In doing so, I am running into issues with EF Core and inserts.
如果我插入1或2行,则EF Core执行普通的SQL INSERT 语句。
If I insert 1 or 2 rows then EF Core performs a normal SQL INSERT statement.
但是当我有3行或更多行时,它会切换到 MERGE 语句,该语句将失败并显示:
But when I have 3 or more rows, it switches to a MERGE statement, which then fails with:
不允许使用列引用 inserted.MyKeyColumn,因为它引用的是未在此语句中修改的基表。
The column reference "inserted.MyKeyColumn" is not allowed because it refers to a base table that is not being modified in this statement.
我的猜测是,这是由于查询实际上在具有插入触发器的视图上运行以更新
My guess is that this is due to the fact that the query is actually running on a view that has an insert trigger on it to update the actual table(s) under the view.
就像我说的那样,当它使用插入语句时,这种方法就很好了。
Like I said, this works just fine when it uses insert statements. But it fails when it tries to insert using a merge.
有没有办法阻止EF Core使用 MERGE 用于插入?
Is there a way to stop EF Core from using MERGE for inserts?
推荐答案因此,更多研究显示了一种强制使用单个插入的方法:
So some more research showed a way to force the use of single inserts:
optionsBuilder.UseSqlServer(connectionString, options => { options.MaxBatchSize(1); });警告:这将导致所有插入都是单独的插入语句。对于大容量刀片来说效果不佳。
Warning: This will cause all inserts to be individual insert statements. Not very performant for high volume inserts.
更多推荐
阻止EF Core使用合并插入
发布评论