【发布时间】:2015-03-10 11:10:16
【问题描述】:
是否可以在将它们写入数据库的同一事务中读取(即选择)列?
我的代码如下所示:
using (IGenericTransaction trans = m_GenericSession.BeginTransaction())
{
//persist a column to table tExample with Id = 1
WriteSubItems();
trans.Commit();
}
public void WriteSubItems()
{
IDbTransaction trans = GetTransaction();
//SELECT column from tExample with Id = 1
}
WriteSubItems 执行一些基于读取之前写入事务中的列的逻辑。
我试过了:
public IDbTransaction GetTransaction()
{
IDbCommand cmd = Session.Connection.CreateCommand())
cmd .Connection = Session.Connection;
Session.Transaction.Enlist(cmd );
return command.Transaction;
}
但没有成功。尝试读取 tExample 总是返回空结果集。当我调用 Session.Transaction.Commit() 时,所有行都添加到数据库中,但事务仍然没有正确传递给 command.Transaction 或者它没有在那里使用
【问题讨论】:
标签: c# sql nhibernate