Skip to content

Support for Temporary Tables in EF Core and Bulk operations #24316

@jstachera

Description

@jstachera

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).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions