【问题标题】:C# Can not execute mysql stored procedure by NhibernateC# 无法通过 Nhibernate 执行 mysql 存储过程
【发布时间】:2016-03-29 05:01:49
【问题描述】:

我不知道如何通过 NHibernate 调用存储过程。所以我搜索并编码如下。但是我得到了错误

例程的 OUT 或 INOUT 参数 3 不是 BEFORE 触发器中的变量或 NEW 伪变量

存储过程:

DELIMITER $$
USE ih$$
DROP PROCEDURE IF EXISTS ms_getDate$$
CREATE DEFINER=root@% PROCEDURE ms_getDate(OUT datetype VARCHAR(2))
BEGIN
    SET datetype = 0;
    SELECT a.Type into datetype 
    FROM hr_employees a WHERE a.Flag= '1';
END$$
DELIMITER;

C#

NHibernate

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" >
  <sql-query name="ms_getDate"  callable="true" >
    <return-scalar column="datetype" type="String" />
    call ms_getDate
  </sql-query>
</hibernate-mapping>

代码

public class At_InsertPlanningStoredProcedure
{
    public virtual int datetype { get; set; }
}

using (DbSession dbSession = new DbSession())
{
 try
  {
    IQuery query = dbSession.session.GetNamedQuery("at_insertplanning");
    At_InsertPlanningStoredProcedure a = query.UniqueResult<At_InsertPlanningStoredProcedure>();
  }catch (Exception ex){}

 }

【问题讨论】:

    标签: c# mysql stored-procedures nhibernate


    【解决方案1】:

    您需要删除参数并使用以下方法返回值:

    CREATE DEFINER=root@% PROCEDURE ms_getDate()
    BEGIN
        SELECT a.Type as datetype 
        FROM hr_employees a WHERE a.Flag= '1';
    END
    

    目前,您将此作为参数,但在调用过程时,您没有指定它。

    像往常一样,如果您使用过 NHProfiler,您自己很容易找到它。

    【讨论】:

      猜你喜欢
      • 2014-09-30
      • 2011-11-03
      • 1970-01-01
      • 2010-11-02
      • 1970-01-01
      • 2019-05-18
      • 1970-01-01
      • 2016-03-06
      • 2016-10-11
      相关资源
      最近更新 更多