TransactionScope问题

时间:2012-02-20 11:09:40

标签: c# nhibernate transactionscope

我在DB中有一个id为7的映射表,字段Taex的值为“qwe”

在此代码中:

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.
}

我需要将db原始数据导入到事务中,我该怎么办?

2 个答案:

答案 0 :(得分:1)

NHibernate有Refresh方法。您可以使用它来强制NH从DB重新加载实体

答案 1 :(得分: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.
}