我正在使用开发我的应用程序Visual Estudio 2010 c#,nhibernate queryover,silverlight 5,在这部分所有工作正常的数据访问部分我用这个:
using (var session = NHibernateFactory.OpenSession())
{
ClassAlias ca = null;
var x = session.QueryOver<SomeClass>()
.Where(root=>root.SomeField > somefield)
.SelectList(list=>list
.Select(root=>root.SomeField1).WithAlias(()=>ca.SF1)
...
.Select(root=>root.SomeFieldN).WithAlias(()=>ca.SF2)
)
.UnderlyingCriteria.SetResultTransformer(
Transformers.AdvanceEntityMapTransformer<ClassAlias>())
.List<ClassAlias>();
}
所有的数据访问都是select语句,所以问题是当我用mono发布我的应用程序进入linux环境时,我开始得到这个间歇性的错误:
16:51:45.488 [Threadpool worker] ERROR NHibernate.Transaction.AdoTransaction - Begin transaction failed
System.NotImplementedException: The requested feature is not implemented.
at MySql.Data.MySqlClient.MySqlConnection.EnlistTransaction (System.Transactions.Transaction transaction) [0x00000] in <filename unknown>:0
at MySql.Data.MySqlClient.MySqlConnection.Open () [0x00000] in <filename unknown>:0
at NHibernate.Connection.DriverConnectionProvider.GetConnection () [0x00000] in <filename unknown>:0
这个日志是来自nhibernate的一般日志文件,我认为我没有找到修复它的方法,任何帮助都会得到真正的好处
我添加了一个自定义日志来捕获异常,并确保nhibernate中的这个异常导致我的查询失败,就是这种情况,这是例外:
ERROR serverAppLog - custom error message
NHibernate.Exceptions.GenericADOException: could not execute query
[ SELECT this_.list_id as y0_, this_.list_name as y1_ FROM vicidial_lists this_ ]
[SQL: SELECT this_.list_id as y0_, this_.list_name as y1_ FROM vicidial_lists this_] ---> System.NotImplementedException: The requested feature is not implemented.
at MySql.Data.MySqlClient.MySqlConnection.EnlistTransaction (System.Transactions.Transaction transaction) [0x00000] in <filename unknown>:0
at MySql.Data.MySqlClient.MySqlConnection.Open () [0x00000] in <filename unknown>:0
at NHibernate.Connection.DriverConnectionProvider.GetConnection () [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at NHibernate.Loader.Loader.DoList (ISessionImplementor session, NHibernate.Engine.QueryParameters queryParameters) [0x00000] in <filename unknown>:0
at NHibernate.Loader.Loader.ListIgnoreQueryCache (ISessionImplementor session, NHibernate.Engine.QueryParameters queryParameters) [0x00000] in <filename unknown>:$
at NHibernate.Loader.Loader.List (ISessionImplementor session, NHibernate.Engine.QueryParameters queryParameters, ISet`1 querySpaces, NHibernate.Type.IType[] resu$
at NHibernate.Loader.Criteria.CriteriaLoader.List (ISessionImplementor session) [0x00000] in <filename unknown>:0
at NHibernate.Impl.SessionImpl.List (NHibernate.Impl.CriteriaImpl criteria, IList results) [0x00000] in <filename unknown>:0
答案 0 :(得分:1)
如果您正在使用System.Transactions / TransactionScope(它似乎来自您的堆栈跟踪),那么我怀疑这是因为事务正在升级为分布式事务(即DTC)。
通常,如果您尝试在同一TransactionScope中访问两个不同的事务资源,则会发生这种情况 - 例如。两个不同的数据库(或相同的数据库,但连接字符串不同),或MSMQ和数据库。
问题是大多数MySql驱动程序不支持DTC - 这就是导致抛出此异常的原因。您有很多选择: