使用烏鴉客戶端和服務器#30155。我基本上做以下的控制器:如何加載文件從數據庫中,而不是存儲
public ActionResult Update(string id, EditModel model)
{
var store = provider.StartTransaction(false);
var document = store.Load<T>(id);
model.UpdateEntity(document) // overwrite document property values with those of edit model.
document.Update(store); // tell document to update itself if it passes some conflict checking
}
然後在document.Update,我試着這樣做:
var old = store.Load<T>(this.Id);
if (old.Date != this.Date)
{
// Resolve conflicts that occur by moving document period
}
store.Update(this);
現在,我遇到的問題是old
被載入了內存而不是數據庫並且已經包含更新的值。因此,它永遠不會進入衝突檢查。
我試圖通過改變Controller.Update
方法爲解決該問題:
public ActionResult Update(string id, EditModel model)
{
var store = provider.StartTransaction(false);
var document = store.Load<T>(id);
store.Dispose();
model.UpdateEntity(document) // overwrite document property values with those of edit model.
store = provider.StartTransaction(false);
document.Update(store); // tell document to update itself if it passes some conflict checking
}
這使得我越來越帶有文本Raven.Client.Exceptions.NonUniqueObjectException
:Attempted to associate a different object with id
現在,問題:
如果我嘗試爲什麼烏鴉照顧和id爲一個新的對象,只要關聯的新對象進行適當的電子標籤和類型?
是否有可能加載一個文件在其數據庫中的狀態(覆蓋默認行爲,如果它存在有從內存中讀取文件)?
什麼是使
document.Update()
工作的最佳解決方案(最好不必傳遞舊對象)?
我可能會忽略一些東西,但這與我的問題有什麼關係?我沒有嘗試在多個會話中編輯同一個文檔,我在多個會話中加載文檔,但僅在一個會話中進行變更。將此屬性設置爲true不會阻止「NonUniqueObjectException」,並且它無助於事實I無法獲得文檔的實際數據庫版本。 – Chrotenise
在這種情況下,請保留舊會話的etag,然後調用Store(entity,etag);這將強制併發檢查服務器端。 –