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

Using xmin concurrency token removes ability to delete without loading entity #1889

Closed
evolvedlight opened this issue Jun 15, 2021 · 2 comments

Comments

@evolvedlight
Copy link

Hi,

I have the following table:

    public class Example
    {
        public int Id { get; set; }

        [Timestamp]
        [DatabaseGenerated(DatabaseGeneratedOption.Computed)]
        [Column("xmin", TypeName = "xid")]
        public uint RowVersion { get; set; }
}

I want to delete from that record by ID without having to load it. Using this:

var example = new Example{ Id = 1 };
context.Entry(example).State = EntityState.Deleted;
await context.SaveChangesAsync();

What happens:
We get a concurrency exception, as the query tries to delete where ID = xx and xmin = yy. The xmin isn't the same, so it doesn't work.
What I expected to happen:
It to delete the record.

Or am I making false assumptions here?

@roji
Copy link
Member

roji commented Jun 15, 2021

This behavior is by design; if you're configuring a concurrency token, then you must have the most up-to-date value of that concurrency token in the entity instance when making updates or deleting; this isn't related to PostgreSQL xmin specifically, you should be able to see it with other types of concurrency tokens.

dotnet/efcore#10443 tracks opting out of optimistic concurrency for a specific operation - this could help here. But until that's done, you'll have to load the entity from the database to get the actual xmin value.

@roji roji closed this as completed Jun 15, 2021
@evolvedlight
Copy link
Author

@roji many thanks

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

No branches or pull requests

2 participants