-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Optimistic Offline Lock #2195
Comments
+1 It's also common to have a convention for this. I.e. Look for a property called "Version", "LockVersion" etc. |
Not sure it is a constrain but we don't need to express RowVersion = RowVersoin + 1 in the update pipeline, just passing the value 24 for the example above would work, correct? |
Yes, it just means we need to be able to do the client side increment for all potential types. |
+1, would help for PostgreSQL which has no rowversion (although a workaround with generating values on update via triggers is probably possible) |
+1, We need it :) Not all databases are so productive working with them like sql server. PostgreSQL like roji mentioned does not support rowversion. |
…t this when dotnet/efcore#2195 is implemented.
FYI I found out PostgreSQL does have an automatically-updated xmin column which could be used as a concurrency token, much like SqlServer's rowversion, so this may be less important for PostgreSQL. See npgsql/efcore.pg#19. |
+1 |
@bricelam I implemented this in the Oracle sample provider by auto-generating triggers in Migrations when creating row version columns. |
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
As reported in #32083, I'm very eager to see this feature implemented. Beyond waiting for it to be implemented in EF Core (which looks like it's going to take a while), is it possible to implement through some custom code? If so, how would that look like? |
@asbjornu you can override SaveChanges and have code there which sets the value of the concurrency token to an incremented value. Or if you want this to happen in the database, you can set up triggers to do that there. |
Hello, I would like to present a scenario I am considering. Suppose I have
My question is, how should I override the However, when I add a new line, the order itself is not modified; it is only used to ensure data coherence. Thus, So, how should I override the Thanks so much. |
@ComptonAlvaro first, to ensure your business rule of no more than 5 items per order, I'd recommend considering an insert trigger. That would allow you to ensure, at the database level, that your invariant is always preserved. Second, it seems you're asking for how to manage a concurrency token - that doesn't seem really related to the 5-items-per-order rule above. In any case, yes - you can have a shadow property that's configured as a concurrency token with EF, and then override SaveChanges to enumerate over all modified entities in the context and update the concurrency token. |
Many databases (including
PostgreSQLand SQLite) don't have an equivalent to SQL Server'srowversion
type. We could improve our support for optimistic concurrency on those stores by implementing the Optimistic Offline Lock pattern in the framework.This would be similar to having a
rowversion
property in the entity except that EF would manage the value. When the entity is saved, somewhere in the update pipeline, we would automatically increment the property's value. The DML would look something like this:The text was updated successfully, but these errors were encountered: