简体   繁体   中英

ConcurrencyCheck throws OptimisticConcurrencyException on first single update

I'm doing a simple update and it works if I won't modify the field that I decorated with [ConcurrencyCheck] attribute.

This is my property:

[Required]
[Index]
[Display(Name="First Name")]
[ConcurrencyCheck]
public string firstname { get; set; }

This is my update action method:

[HttpPost]
[Err()]
public async Task<ActionResult> Edit(Entries entry)
 {
     if (ModelState.IsValid)
     {
            CtxRepoRBMS<CarlCtx, Entries> ctxRDMS = HttpContext.GetOwinContext().Get<CtxRepoRBMS<CarlCtx, Entries>>();
            MongoRepo<Items> ctxMongo = new MongoRepo<Items>(client: new MongoClient("mongodb://localhost"), dbName: "items");

            ctxRDMS.Update(entry);
            ctxRDMS.Save();

ctxRDMS.Update is:

public void Update(Cls entry)
{
       ctx.Entry(entry).State = EntityState.Modified;
}

and ctxRDBMS.Save is

public void Save()
{
   ctx.SaveChanges();
}

The update works fine if i will modify other properties except firstname , but as soon as I change it and save it will throw the OptimisticConcurrencyException which doesn't make sense because there is no one else editing firstname other than me.

I think I have just figured this one out.

If a column is decorated with [concurrencycheck], that column cannot be changed without throwing a concurrency exception (at least I can't change it).

None of the documentation states it so clearly and the examples I see usually choose some column in their example that could well be changed over the life of the data (Last Name, in one case).

The consensus seems to be to use a ROWVERSION column in SQL Server as the only concurrency token in the model.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM