[英]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.我正在做一个简单的更新,如果我不修改我用
[ConcurrencyCheck]
属性修饰的字段,它会起作用。
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: ctxRDMS.Update
是:
public void Update(Cls entry)
{
ctx.Entry(entry).State = EntityState.Modified;
}
and ctxRDBMS.Save
is和
ctxRDBMS.Save
是
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.如果我将修改除
firstname
之外的其他属性,则更新工作正常,但是一旦我更改它并保存它就会抛出OptimisticConcurrencyException
这没有意义,因为除了我之外没有其他人编辑firstname
。
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).如果一列用 [concurrencycheck] 修饰,那么在不抛出并发异常的情况下无法更改该列(至少我无法更改它)。
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.共识似乎是使用 SQL Server 中的 ROWVERSION 列作为模型中唯一的并发令牌。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.