0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【C#】EFCoreのBulkExtensionsでBulkInsertOrUpdateを行う

0
Posted at

概要

C#のORM、EFCoreでUpsertを行う場合にどうするかのメモ書きです。EFCore.BulkExtensionsを使用して今回は実装します。

前提

  • 使用したEFCore.BulkExtensionsのバージョンは10.0.0です。
  • 使用したRDBはPostgreSQLです。

実装サンプル

実装自体はシンプルで、InsertOrUpdateを行うentityのlistを引数に渡して実行します。

using EFCore.BulkExtensions;

public class SampleRepository(ApplicationDbContext _context) : ISampleRepository
{
    private readonly ApplicationDbContext dbContext = _context;

    public void InsertOrUpdateSampleEntities(List<SampleEntity> entities)
    {
        dbContext.BulkInsertOrUpdate(entities);
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?