C#实体框架:仅更新第一批记录并停止 [英] C# Entity Framework: Update Only First Batch Records and Stop

查看:82
本文介绍了C#实体框架:仅更新第一批记录并停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

EF Core Bulk扩展是否可以只更新前几万行?写消息,更新下一个批处理,循环写消息直到完成?

Is there way with EF Core Bulk extensions to only update first few 10000 rows? write message, update next batch, write message in loop until complete?

我知道有批处理大小,但是如果只有500万要更新,我只想更新一定数量,写一个消息,不断循环直到完成,该怎么做?

I know there is Batch Size, however if there is only 5 million to update, and I want only update a certain amount, write a message, in continual loop until complete, how can this be done?

我应该使用顶还是走?

我想写

while {

await _dbContext.Set<Product>()
    .Where(x => x.Manufacturer == "ABC Company" &&
                x.StartYear == 2019 &&
                x.ProductType.ProductTypeDescription == "Electronics")
    .BatchUpdateAsync(x => new Product(){
                Manufacturer = "XYZ Company",
                StartYear = 2020 });

Console.WriteLine("hello"):

https://github.com/borisdj/EFCore.BulkExtensions

使用EF Core 3.1。

Using EF Core 3.1.

公司不想使用SignalR

Company does not want to use SignalR

推荐答案

BatchSize似乎是仅用于批量插入。为了进行更新,表达式被转换为单个SQL UPDATE语句,该语句不能由批处理操作。

It looks like BatchSize is only used for bulk insert. For update the expression is translated to a single SQL UPDATE statement, which doesn't operate by "batches".

这篇关于C#实体框架:仅更新第一批记录并停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆