如何在c#中使用NHibernate获取输出参数的mysql存储过程的值?
这里我的MySql存储过程如下:
CREATE DEFINER=`root`@`localhost` PROCEDURE `SaveEmployeeOutParamSP`(
IN Nameparam VARCHAR(30),
IN Mobileparam VARCHAR(20),
IN Sexparam BIT(1),
OUT MaxIDOut INT,
OUT TotalCOuntOut INT
)
BEGIN
INSERT INTO Test
(
Name,
Mobile,
Sex
)
VALUES (
Nameparam,
Mobileparam,
Sexparam
);
SELECT MAX(ID) FROM Test
INTO MaxIDOut;
SELECT COUNT(*) FROM Test
INTO TotalCOuntOut;
END
这是我的NHibernate代码:
public void SaveGetEmployeeSP(EmployeeEntity employeeEntity)
{
IQuery query = NHSession.CreateSQLQuery("CALL SaveEmployeeOutParamSP (:Name, :Mobile, :Sex, :MaxIDOut, :TotalCOuntOut)");
query.SetParameter("Name", employeeEntity.Name);
query.SetParameter("Mobile", employeeEntity.Mobile);
query.SetParameter("Sex", employeeEntity.Sex);
query.SetParameter("MaxIDOut", "@MaxIDOut");
query.SetParameter("TotalCOuntOut", "@TotalCOuntOut");
var obj = query.UniqueResult();
}
以上代码抛出的异常如下:
An unhandled exception of type 'NHibernate.Exceptions.GenericADOException' occurred in NHibernate.dll
Additional information: could not execute query
[ CALL SaveEmployeeOutParamSP(?p0, ?p1, ?p2, ?p3, ?p4) ]
Name:Name - Value:2 Name:Mobile - Value:18 Name:Sex - Value:18 Name:MaxIDOut - Value:@MaxIDOut Name:TotalCOuntOut - Value:@TotalCOuntOut
[SQL: CALL SaveEmployeeOutParamSP(?p0, ?p1, ?p2, ?p3, ?p4)]
所以任何解决方案 -