2012-02-20 94 views
0

我在DB id爲7的映射表,字段Taex值爲「QWE」的TransactionScope問題

在此代碼

var fooObj = Foo.GetById(7); 
fooObj.Taex = "abc"; 
using (new TransactionScope(OnDispose.Rollback)) 
{ 
    var originalFooObj = Foo.GetById(7); 
    // how can i do to get real original object from database into a transaction 
    bool areEquals = fooObj.Taex == originalFooObj.Taex; // are equals 
    // because nhibernate gets the cached object. 
} 

我需要的數據庫原始數據轉化爲交易,怎麼能我做 ?

+0

我試圖使用ActiveRecordMediator.Evict(fooObj),但不起作用,我試圖克隆對象,但是,作爲屬性的惰性對象(其他實體)通過通過參考,我會克隆他們,一些想法? – manuellt 2012-02-20 13:43:37

回答

1

NHibernate的有Refresh方法。您可以使用它來強制NH重新加載實體從DB

0

,你就沒有它已經:

var fooObj = Foo.GetById(7); 
var tempTaex = fooObj.Taex; //**get the original value 
fooObj.Taex = "abc"; 
using (new TransactionScope(OnDispose.Rollback)) 
{ 
    var originalFooObj = Foo.GetById(7); 
    // how can i do to get real original object from database into a transaction 
    bool areEquals = fooObj.Taex == tempTaex; //**use it 
    // because nhibernate gets the cached object. 
} 
+0

Thanx,但範圍是從數據庫中獲取原始數據,這只是一個例子,在現實世界的應用程序中它更復雜。 – manuellt 2012-02-20 13:41:12