Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Blog - Optimistic concurrency with MySQL and Entity Framework
Property(x => x.Version).IsRequired()
.IsConcurrencyToken()
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed);
var concurrencyTokenEntries = ChangeTracker.Entries<IVersionedEntity>();
foreach (var entry in concurrencyTokenEntries)
{
if (entry.State == EntityState.Unchanged)
{
continue;
}
entry.Entity.Version = Guid.NewGuid();
}
TIMESTAMP type with default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
Property(x => x.Version).IsRequired()
.IsConcurrencyToken()
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
public System.Guid Version { get; set; }
public interface IVersionedEntity
{
Guid Version { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment