我正在使用 efcore.bulkextensions 在表中插入和更新记录。但是我的状态更新记录有问题。
例如,我有15个记录(10个记录,插入5个记录,5个更新)。我需要插入10,但仅更新2个,因为3个记录在更新的属性中具有旧值(数据库包含更多最新数据)。
如果我使用 efcore.bulkextensions 这样:
_dbContext.BulkInsertOrUpdateAsync(entitiesList, _bulkConfig);
将插入10个记录,并将更新5个记录。因此,数据库中的数据将由较旧的数据进行更新。
为了解决我的问题,我想要这样的问题:
_dbContext.BulkInsertOrUpdateAsync(entitiesList, _bulkConfig,
(oldRecord, newRecord) => newRecord.UpdatedAt > oldRecord.UpdatedAt);
您能否提出一些有效的方法来解决此问题,以 efcore.bulkextensions ?
I am using EFCore.BulkExtensions for insert and update records in a table. But I have a problem with update records on condition.
For example, I have 15 records (10 to insert, 5 to update). I need to insert 10, but update only 2, because 3 records have old value in UpdatedAt property (database contains more recent data).
If I use EFCore.BulkExtensions like this:
_dbContext.BulkInsertOrUpdateAsync(entitiesList, _bulkConfig);
10 records will be inserted and 5 records will be updated. So the data in the database will be updated by older ones.
To solve my problem I want something like this:
_dbContext.BulkInsertOrUpdateAsync(entitiesList, _bulkConfig,
(oldRecord, newRecord) => newRecord.UpdatedAt > oldRecord.UpdatedAt);
Can you suggest some efficient way to solve this problem with EFCore.BulkExtensions?
发布评论
评论(1)
这不是
efcore.bulkextensions
的直接答案,而是使用。请注意,我是创作者之一。为EF Core 2.x选择适当的软件包2.x,EF Core 3.1.x的3.x,等。
This is not direct answer for
EFCore.BulkExtensions
, but alternative how to do that with linq2db.EntityFrameworkCore. Note that I'm one of the creators.Select appropriate package 2.x for EF Core 2.x, 3.x for EF Core 3.1.x, etc.