Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table splitting + ConcurrencyToken throws unexpected DBConcurrencyException #33750

Open
Westboldyi opened this issue May 18, 2024 · 4 comments
Open

Comments

@Westboldyi
Copy link

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:

//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<Foo>
    {
        public void Configure(EntityTypeBuilder<Foo> builder)
        {
            builder.HasKey(p => p.FooId);

            builder.HasOne(p => p.Bar).WithOne().HasForeignKey<Bar>(p => p.FooId);
            builder.HasOne(p => p.Baz).WithOne().HasForeignKey<Baz>(p => p.FooId);

            builder.Property<uint>("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<Baz>
    {
        public void Configure(EntityTypeBuilder<Baz> builder)
        {
            builder.HasKey(p => p.FooId);

            builder.Property<uint>("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<Bar>
    {
        public void Configure(EntityTypeBuilder<Bar> builder)
        {
            builder.HasKey(p => p.FooId);
                        
            builder.Property<uint>("xmin").IsRowVersion();
            builder.ToTable("Table");


        }
    }

}

image

Include provider and version information

EF Core version:
Database provider: Postgresql
Target framework: .NET 8
Operating system: WIN 10
IDE:VS 2022

@roji
Copy link
Member

roji commented May 18, 2024

@Westboldyi can you please submit a minimal, runnable console program that shows the error happening? It's hard to piece together exactly what you're doing from a screenshot and partial snippets.

@Westboldyi
Copy link
Author

Westboldyi commented May 19, 2024

@ajcvickers
Copy link
Member

I believe this is by-design. @AndriySvyryd can you confirm that we require the principal to be tracked for this case?

@AndriySvyryd AndriySvyryd added this to the Backlog milestone Jun 4, 2024
@AndriySvyryd
Copy link
Member

No, this is a bug. We need to either collapse both updates into one command (by indexing using key values instead of entries) or to separate the two commands in different batches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants