Skip to content

BulkMerge with many to many relations configured with fluent api #632

@mrhoga

Description

@mrhoga

Hi,

I have two entities, which have a many-to-many relationship that is configured via fluent API:

public void Configure(EntityTypeBuilder<Medium> builder)
{
     builder.HasMany(m => m.Sperrliste)
                .WithMany(pkzRef => pkzRef.Medien);
}

Medium.Sperrliste is of type List<Sperrkennzeichen>.
here is no entity that represents the many-to-many relationship in code like e.g. MediumSperrkennzeichen.

I tried bulk merging Medium objects with Sperrlisten, but it does not work.
Currently my code looks like this:

await dbContext.BulkMergeAsync(batch, new BulkOperationOptions<Medium>
{
    BatchSize = 10_000,
    IncludeGraph = true,
    IncludeGraphOperationBuilder = operation =>
    {
        switch (operation)
        {
            case BulkOperation<Medium> mediumOperation:
                mediumOperation.ColumnPrimaryKeyExpression = m => new { m.Geschaeftsjahr, m.Nr };
                mediumOperation.ColumnOutputExpression = m => new { Id = (int)m.Id };
                break;
            case BulkOperation<Sperrkennzeichen> sperrkennzeichenOperation:
                sperrkennzeichenOperation.ColumnPrimaryKeyExpression = s => new { s.Id };
                sperrkennzeichenOperation.ColumnOutputExpression = s => new { s.Id };
                break;
        }
    }
}, cancellationToken);

I have no idea how to configure the bulk merge to satisfy the many-to-many relationship without having an entity for that relation?

Thanks in advance and best regards
Holger

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions