我有一个存储过程,除了用户类型作为参数。从Nhibernate调用它时,它抛出以下异常。
从Nhibernate致电
EmployeeType emp = new EmployeeType(243214,"Anupam");
IQuery final = eventhistorysession.CreateSQLQuery("call testCustom (:pLocation)");
final.SetParameter("pLocation", emp, NHibernateUtil.Custom(typeof(EmployeeTypeCustomType)));
int result = final.ExecuteUpdate();
异常堆栈跟踪
NHibernate.Exceptions.GenericADOException was caught
Message="could not execute native bulk manipulation query:call testCustom (:pLocation)[SQL: SQL not available]"
Source="NHibernate"
SqlString="SQL not available"
StackTrace:
at NHibernate.Engine.Query.NativeSQLQueryPlan.PerformExecuteUpdate(QueryParameters queryParameters, ISessionImplementor session)
at NHibernate.Impl.SessionImpl.ExecuteNativeUpdate(NativeSQLQuerySpecification nativeQuerySpecification, QueryParameters queryParameters)
at NHibernate.Impl.SqlQueryImpl.ExecuteUpdate()
at TestDatabase.Program.InsertNhibernate() in C:\Jaroori Kachra\TestDatabase\TestDatabase\Program.cs:line 228
InnerException: System.ArgumentOutOfRangeException
Message="Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index"
Source="mscorlib"
ParamName="index"
StackTrace:
at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
at System.ThrowHelper.ThrowArgumentOutOfRangeException()
at System.Collections.Generic.List1.get_Item(Int32 index)
at NHibernate.Engine.QueryParameters.SetParameterLocation(IList
1 sqlParameters, Int32 parameterIndex, Int32 sqlLocation, Int32 span)
at NHibernate.Engine.QueryParameters.PrepareParameterTypes(SqlString sqlString, ISessionFactoryImplementor factory, GetNamedParameterLocations getNamedParameterLocations, Int32 startParameterIndex, Boolean addLimit, Boolean addOffset)
at NHibernate.Engine.Query.NativeSQLQueryPlan.PerformExecuteUpdate(QueryParameters queryParameters, ISessionImplementor session)
InnerException:
1.get_Item(Int32 index)
at NHibernate.Engine.QueryParameters.SetParameterLocation(IList
我的自定义类
我在oracle中的存储过程和用户定义类型
public class EmployeeTypeCustomType : ICompositeUserType
{
public Type ReturnedClass { get { return typeof(EmployeeType); } }
public new bool Equals( object x, object y ) {
if ( object.ReferenceEquals(x,y) ) return true;
if (x == null || y == null) return false;
return x.Equals(y);
}
public object DeepCopy(object value) { return value; }
public bool IsMutable { get { return false; } }
public object NullSafeGet(IDataReader dr, string[] names, NHibernate.Engine.ISessionImplementor session, object owner) {
object obj0 = NHibernateUtil.Decimal.NullSafeGet(dr, names[0]);
object obj1 = NHibernateUtil.String.NullSafeGet(dr, names[1]);
if ( obj0==null || obj1==null ) return null;
decimal value = (decimal) obj0;
string currency = (string) obj1;
return new EmployeeType(value, currency);
}
public void NullSafeSet(IDbCommand cmd, object obj, int index, NHibernate.Engine.ISessionImplementor session) {
if (obj == null) {
((IDataParameter)cmd.Parameters[index]).Value = DBNull.Value;
((IDataParameter)cmd.Parameters[index+1]).Value = DBNull.Value;
} else {
EmployeeType amount = (EmployeeType)obj;
((IDataParameter)cmd.Parameters[index]).Value = amount.EmployeeId;
((IDataParameter)cmd.Parameters[index+1]).Value = amount.EmployeeName;
}
}
public string[] PropertyNames {
get { return new string[] { "EmployeeId", "EmployeeName" }; }
}
public NHibernate.Type.IType[] PropertyTypes {
get { return new NHibernate.Type.IType[] {
NHibernateUtil.Decimal, NHibernateUtil.String }; }
}
public object GetPropertyValue(object component, int property) {
EmployeeType amount = (EmployeeType)component;
if (property == 0)
return amount.EmployeeId;
else
return amount.EmployeeName;
}
public void SetPropertyValue(object comp, int property, object value) {
throw new Exception("Immutable!");
}
public object Assemble(object cached,
NHibernate.Engine.ISessionImplementor session, object owner) {
return cached;
}
public object Disassemble(object value,
NHibernate.Engine.ISessionImplementor session) {
return value;
}