Table splitting + ConcurrencyToken throws unexpected DBConcurrencyException
- Dominant language
- C#
- Stars
- 14.8k
- Forks
- 3.4k
- PR merge metrics
- PR metrics pending
Description
When configuring multiple entities with table splitting and row version concurrency tokens, updating the dependents without the principal entity will throw an unexpected `DbUpdateConcurrencyException`.
If the principal entity (`Foo`) is tracked via ChangeTracker, then the updates persist properly. This occurs regardless of whether a transaction is used or not.
EF Configs:
```C#
//Principal
public class Foo
{
public string FooProp { get; set; }
public string FooId { get; set; } = Guid.NewGuid().ToString();
public Bar Bar { get; set; }
public Baz Baz { get; set; }
private class FooConfig : IEntityTypeConfiguration
{
public void Configure(EntityTypeBuilder builder)
{
builder.HasKey(p => p.FooId);
builder.HasOne(p => p.Bar).WithOne().HasForeignKey(p => p.FooId);
builder.HasOne(p => p.Baz).WithOne().HasForeignKey(p => p.FooId);
builder.Property("xmin").IsRowVersion();
builder.ToTable("Table");
}
}
}
//Dependent 1
public class Baz
{
public string Property1 { get; set; } = "prop1";
public string FooId { get; set; } = Guid.NewGuid().ToString();
private class BazConfig : IEntityTypeConfiguration
{
public void Configure(EntityTypeBuilder builder)
{
builder.HasKey(p => p.FooId);
builder.Property("xmin").IsRowVersion();
builder.ToTable("Table");
}
}
}
//Dependent 2
public class Bar
{
public string Property2 { get; set; } = "prop2";
public string FooId { get; set; } = Guid.NewGuid().ToString();
private class BarConfig : IEntityTypeConfiguration
{
public void Configure(EntityTypeBuilder builder)
{
builder.HasKey(p => p.FooId);
builder.Property("xmin").IsRowVersion();
builder.ToTable("Table");
}
}
}
```

### Include provider and version information
EF Core version:
Database provider: Postgresql
Target framework: .NET 8
Operating system: WIN 10
IDE:VS 2022
Contributor guide
Assessment
This issue has not been assessed yet.