阻止EF Core使用合并插入

编程入门 行业动态 更新时间:2024-10-21 18:47:05
本文介绍了阻止EF Core使用合并插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在将我的应用程序转换为.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使用合并插入

本文发布于:2023-11-17 04:45:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1608877.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:EF   Core

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!