![](/img/trans.png)
[英]Is it possible to query Entity Framework before calling DbContext.SaveChanges?
[英]Entity Framework 6 - Is there any way to get new rowversion from DbContext.SaveChanges()?
var ctxLog = new List<string>();
var accountToUpdate = sAccount.ToEntity();
// sAccount is DTO !
ctx.accounts.Attach(accountToUpdate);
ctx.Entry(accountToUpdate).State = EntityState.Modified;
accountToUpdate.dt_stamp = BllUtils.GetServerDateTime(ctx);
var log = ctxLog;
ctx.Database.Log = s => log.Add(s);
ctx.SaveChanges();
在上面的SaveChanges()
之后的代碼中, accountToUpdate.rowversion
仍然是舊的。
有沒有一種方法可以在不對數據庫運行新查詢的情況下獲取新的rowversion
值?
保存更改后, ctx.Entry(accountToUpdate).GetDatabaseValues();
並檢查accountToUpdate.rowversion
值是否已更改。 這可能有效
在EF的StoreGeneratedPattern
版本中,我在字段上使用StoreGeneratedPattern
屬性。 這將在插入/更新后獲取內容。 我真的不知道是否會導致另一次往返。 您可以在此博客文章中找到更多信息
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.