I am trying to do massive update based on primary key for around 2,000,000 of records.
The Id's which needs to be updated are stored in the file.
I did not find any easy way with EF Core to do this update without round-trip (client-db).
The current solution was to have simple Id table:
create table if not exists "ValidIdentifiers" ( "Id" integer not null );
before the update that table is cleaned by:
await DbContext.Database.ExecuteSqlRawAsync("TRUNCATE TABLE \"ValidIdentifiers\"");
and I am using third part tool (https://entityframework-extensions.net/bulk-insert) to insert 2M records:
await DbContext.BulkInsertAsync(ids, options => { options.AutoMapOutputDirection = false; options.UseTableLock = true; });
To do update for those 2M records I use:
DbContext.Database.ExecuteSqlRawAsync($"UPDATE \"{some_table}\" SET \"DeleteDate\" = current_date WHERE \"DeleteDate\" is null AND date(\"UploadDate\") < date(current_date) AND \"Id\" in (SELECT \"Id\" FROM \"{some_table}\" EXCEPT SELECT \"Id\" FROM \"ValidIdentifiers\")");
Firstly It would be good to have ability to create temporary tables.
Secondly there is a need for bulk operations in EF Core (INSERT/UPDATE/DELETE).
I am trying to do massive update based on primary key for around 2,000,000 of records.
The Id's which needs to be updated are stored in the file.
I did not find any easy way with EF Core to do this update without round-trip (client-db).
The current solution was to have simple Id table:
create table if not exists "ValidIdentifiers" ( "Id" integer not null );before the update that table is cleaned by:
await DbContext.Database.ExecuteSqlRawAsync("TRUNCATE TABLE \"ValidIdentifiers\"");and I am using third part tool (https://entityframework-extensions.net/bulk-insert) to insert 2M records:
await DbContext.BulkInsertAsync(ids, options => { options.AutoMapOutputDirection = false; options.UseTableLock = true; });To do update for those 2M records I use:
DbContext.Database.ExecuteSqlRawAsync($"UPDATE \"{some_table}\" SET \"DeleteDate\" = current_date WHERE \"DeleteDate\" is null AND date(\"UploadDate\") < date(current_date) AND \"Id\" in (SELECT \"Id\" FROM \"{some_table}\" EXCEPT SELECT \"Id\" FROM \"ValidIdentifiers\")");Firstly It would be good to have ability to create temporary tables.
Secondly there is a need for bulk operations in EF Core (INSERT/UPDATE/DELETE).