我正在尝试将NHibernate与.NET的TransactionScope对象结合使用.到目前为止,我已经成功地使用了Oracle 11g和SQL Server 2008R2,没有任何问题.但是,SQL Compact似乎已面目全非.
I am trying to use NHibernate in combination with .NET's TransactionScope object. So far I have successfully used Oracle 11g and SQL Server 2008R2 with no issues. However, SQL Compact seems to fall on its face.
using (var scope = new TransactionScope(TranactionScopeOption.Required)) { using (var session = _sessionFactory.OpenSession()) { // The line below throws. I also tried passing in System.Data.IsolationLevel.ReadCommitted to no avail using (var txn = session.BeginTransaction()) { // Perform insert txn.Commit(); } } scope.Complete(); }这导致以下异常.我知道这是什么意思,但我不明白为什么为什么尝试创建嵌套事务.
This results in the following exception. I understand what this means, but I don't understand why it is attempting to create a nested transaction.
NHibernate.TransactionException: Begin failed with SQL exception ---> System.InvalidOperationException: SqlCeConnection does not support nested transactions. at System.Data.SqlServerCe.SqlCeConnection.BeginTransaction(IsolationLevel isolationLevel) at System.Data.SqlServerCe.SqlCeConnection.BeginDbTransaction(IsolationLevel isolationLevel) at System.Data.Common.DbConnection.System.Data.IDbConnection.BeginTransaction(IsolationLevel isolationLevel) at NHibernate.Transaction.AdoTransaction.Begin(IsolationLevel isolationLevel) at NHibernate.Transaction.AdoTransaction.Begin(IsolationLevel isolationLevel)推荐答案
我认为答案就在这个问题上:无法在交易范围内征用连接对象
I think the answer lies in this question: The connection object can not be enlisted in transaction scope
猜测中,TransactionScope需要升级为分布式或嵌套事务,CE都不支持."
"At a guess, TransactionScope needs to escalate to a distributed or nested transaction, neither of which is supported by CE."
更多推荐
如何在SQL Compact 4.0和NHibernate中使用TransactionScope
发布评论