Optimistic concurrency: IsConcurrencyToken and RowVersion

后端 未结 3 1815
萌比男神i
萌比男神i 2020-12-01 10:56

I\'m creating the default concurrency strategy that I will use in my application.

I decided for an optimistic strategy.

All of my entities are mapped as

3条回答
  •  眼角桃花
    2020-12-01 11:43

    The problem is not how you are setup. What is happening is that the OriginalValue of your RowVersion entry is set to the new value as soon as you pull it out of the Context.

     var carInstance = dbContext.Cars.First();
     carInstance.RowVersion = carDTO.RowVerison;
     carInstance.Color = carDTO.Color ;
    
    
     var entry = dbContext.Entry(carInstance); //Can also come from ChangeTrack in override of SaveChanges (to do it automatically)     
    
     entry.Property(e => e.RowVersion)
                        .OriginalValue = entry.Entity.RowVersion;
    

提交回复
热议问题