0

I have an entity that has an ID field, as well as few other properties who are set on unique index.

await _context.Declarations.BulkInsertAsync(declarations, o =>
        {
            o.IncludeGraph = true;
                    
            o.InsertIfNotExists = true;
            o.IncludeGraphOperationBuilder = bo =>
                     {
            if (bo is BulkOperation<DeclarationEntity>)
            {
                o.ColumnPrimaryKeyExpression = c => new
                    { c.Code, c.Version, c.Year, c.DeclarationNumber };
            }
        };
    }, cancellationToken);
await _context.BulkSaveChangesAsync(cancellationToken);

The entity:

[Table("Declarations")]
[Index(nameof(Year), nameof(DeclarationNumber), nameof(Version), nameof(Code), IsUnique = true)]
public class DeclarationEntity
{
    public int Id { get; set; }

    public int Year { get; set; }
    public string DeclarationNumber { get; set; }
    public string Code { get; set; }
    public int Version { get; set; } 

    public IList<Item> Items { get; set; }
}

When I try to insert an entity which violates the index I get the exception of course. However, is it possible to pass an entity to BulkInsert/Save that would still violate the index but it would just be skipped (not inserted)? Primary key is the ID field, and not these 4 fields.

Oracle is the DB provider, if that matters.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Mefhisto1
  • 2,188
  • 7
  • 34
  • 73

0 Answers0