我试图在NHibernate 3.2和Oracle 11gR2中使用期货.虽然我不确定,但这似乎并不支持.我在NHibernate Jira上找到了
this issue,这看起来甲骨文似乎可能有未来.有谁知道如何让期货与Oracle合作? Oracle不受支持的原因究竟是什么?
更新
根据这里的评论,我尝试使用HQL multiquery.我在执行_nhSession.CreateMultiQuery()时遇到异常;这是例外:
The driver NHibernate.Driver.OracleDataClientDriver does not support multiple queries.
我还能尝试什么?我使用了错误的驱动程序吗?
我想分享一下NHibernate Future查询如何与Oracle协同工作的方式.您可以将以下两个类EnhancedOracleDataClientDriver和EnhancedOracleResultSetsCommand添加到您的项目中,并将NHibernate配置为使用EnhancedOracleDataClientDriver类作为数据库驱动程序.我很感激这种方法是否适用于其他人的反馈.这是上述类的源代码.
原文链接:https://www.f2er.com/oracle/205005.htmlEnhancedOracleDataClientDriver.cs
using NHibernate.Engine; namespace NHibernate.Driver { public class EnhancedOracleDataClientDriver : OracleDataClientDriver { public override bool SupportsMultipleQueries { get { return true; } } public override IResultSetsCommand GetResultSetsCommand(ISessionImplementor session) { return new EnhancedOracleResultSetsCommand(session); } } }
EnhancedOracleResultSetsCommand.cs
using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Reflection; using NHibernate.Engine; using NHibernate.sqlCommand; using NHibernate.sqlTypes; using NHibernate.Util; namespace NHibernate.Driver { public class EnhancedOracleResultSetsCommand : BasicResultSetsCommand { private const string driverAssemblyName = "Oracle.DataAccess"; private sqlString sqlString = new sqlString(); private int cursorCount = 0; private readonly PropertyInfo oracleDbType; private readonly object oracleDbTypeRefCursor; public EnhancedOracleResultSetsCommand(ISessionImplementor session) : base(session) { System.Type parameterType = ReflectHelper.TypeFromAssembly("Oracle.DataAccess.Client.OracleParameter",driverAssemblyName,false); oracleDbType = parameterType.GetProperty("OracleDbType"); System.Type oracleDbTypeEnum = ReflectHelper.TypeFromAssembly("Oracle.DataAccess.Client.OracleDbType",false); oracleDbTypeRefCursor = System.Enum.Parse(oracleDbTypeEnum,"RefCursor"); } public override void Append(IsqlCommand command) { Commands.Add(command); sqlString = sqlString.Append("\nOPEN :cursor") .Append(Convert.ToString(cursorCount++)) .Append("\nFOR\n") .Append(command.Query).Append("\n;\n"); } public override sqlString sql { get { return sqlString; } } public override IDataReader GetReader(int? commandTimeout) { var batcher = Session.Batcher; sqlType[] sqlTypes = Commands.SelectMany(c => c.ParameterTypes).ToArray(); ForEachsqlCommand((sqlLoaderCommand,offset) => sqlLoaderCommand.ResetParametersIndexesForTheCommand(offset)); sqlString = sqlString.Insert(0,"\nBEGIN\n").Append("\nEND;\n"); var command = batcher.PrepareQueryCommand(CommandType.Text,sqlString,sqlTypes); if (commandTimeout.HasValue) { command.CommandTimeout = commandTimeout.Value; } BindParameters(command); for (int cursorIndex = 0; cursorIndex < cursorCount; cursorIndex++) { IDbDataParameter outCursor = command.CreateParameter(); oracleDbType.SetValue(outCursor,oracleDbTypeRefCursor,null); outCursor.ParameterName = ":cursor" + Convert.ToString(cursorIndex); outCursor.Direction = ParameterDirection.Output; command.Parameters.Add(outCursor); } return new BatcherDataReaderWrapper(batcher,command); } } }