EntityFrameworkCore.ClickHouse icon indicating copy to clipboard operation
EntityFrameworkCore.ClickHouse copied to clipboard

Error while insert

Open ashish135906 opened this issue 6 months ago • 0 comments

The instance of entity type 'DistributorStockSale' cannot be tracked because another instance with the same key value for {'CompanyId', 'DateKey'} is already being tracked. When attaching existing entities, ensure that only one entity instance with a given key value is attached. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see the conflicting key values.

protected override void OnModelCreating(ModelBuilder modelBuilder) { var entityTypeBuilder = modelBuilder.Entity<DistributorStockSale>();

entityTypeBuilder.HasKey(e => new { e.CompanyId, e.DateKey });

entityTypeBuilder.ToTable("DistributorStockSale", table => table
    .HasMergeTreeEngine()
    .WithPrimaryKey("CompanyId", "DateKey"));

}

I am getting this error while using AddRangeAsync();

If the error i am getting is due to the multiple records with same companyid and datekey being inserted at a time, should not we handle this for clickhouse as clickhouse does not enforce unique primary key concept?

ashish135906 avatar Aug 25 '24 21:08 ashish135906