Skip to content

Support for multiple .On( .. ) for two unique indexes case #176

@AnthonyBreneliereMedhub

Description

I don't find a way to use Flexlabs.Upsert in my case.

I have two unique indexes:
( CompanyId, InternalCode )
( CompanyId, Cip13)

The following command would suit my case, but two On(..) are not supported

await _context.Set<ProductInfoForCompany>()
    .UpsertRange(companyProducts)
    .On(cp => new { cp.InternalCode, cp.CompanyId })
    .On(cp => new { cp.Cip13, cp.CompanyId })
    .WhenMatched(cp => new ProductInfoForCompany
    {
        InternalCode = cp.InternalCode,
        CompanyId = cp.CompanyId,
        Cip13 = cp.Cip13,
        UpdatedAt = DateTime.UtcNow,
    })
    .WithFallbackExpressionCompiler()
    .RunAsync(ct);

With a single On ( .On(cp => new { cp.Cip13, cp.CompanyId }) is missing),

  • if InternalCode has changed, (Cip13, CompanyId ) is not matched. It will then try to insert, and create a duplicate key for (Cip13, CompanyId ).
  • if Cip13 has changed, (InternalCode, CompanyId ) is not matched. It will then try to insert, and create a duplicate key for (InternalCode, CompanyId ).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions