zoukankan      html  css  js  c++  java
  • 转:NHibernate 存储过程

    http://stackoverflow.com/questions/928847/how-to-get-the-return-value-from-a-sql-server-stored-procedure-into-nhibernate

    <?xml version="1.0" encoding="utf-8" ?>
    <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="DocumentManagement.Data" namespace="DocumentManagement.Data.Repositories" >

    <sql-query name="GetDocument">
    <return class="DocumentManagement.Core.Models.PhysicalDocument, DocumentManagement.Core">
    <return-property column="DocId" name="Id" />
    <return-property column="Filepath" name="Filepath" />
    <return-property column="Filename" name="Filename" />
    </return>
    exec Investor_GetDocumentById :userId, :docId
    </sql-query>

    </hibernate-mapping>


    public PhysicalDocument GetDocumentPath(int userId, int docId)
    {
    var query = Session.GetNamedQuery("GetDocument")
    .SetInt32("userId", userId)
    .SetInt32("docId", docId).List<PhysicalDocument>();

    return query[0];
    }

    ISession session = sessionFactory.GetSession();

    using(ITransaction transaction = session.BeginTransaction())
    {
    IDbCommand command = new SqlCommand();
    command.Connection = session.Connection;

    // Enlist IDbCommand into the NHibernate transaction
    transaction.Enlist(command);

    command.CommandType = CommandType.StoredProcedure;
    command.CommandText = "dbo.SetUserInfo";

    // Set input parameters
    var parm = new SqlParameter("@UserID", SqlDbType.Int);
    parm.Value = 12345;
    command.Parameters.Add(parm);

    // Set output parameter
    var outputParameter = new SqlParameter("@Quantity", SqlDbType.Int);
    outputParameter.Direction = ParameterDirection.Output;
    command.Parameters.Add(outputParameter);

    // Set a return value
    var returnParameter = new SqlParameter("@RETURN_VALUE", SqlDbType.Int);
    returnParameter.Direction = ParameterDirection.ReturnValue;
    command.Parameters.Add(returnParameter);

    // Execute the stored procedure
    command.ExecuteNonQuery();
    }

  • 相关阅读:
    php中怎么使用call_user_func动态调用方法
    MYSQL中TIMESTAMP类型的默认值理解
    你可能不知道console强大
    在线文档
    PHP中字符串转换为数值 可能会遇到的坑
    网站推荐
    谷歌搜索语法
    ShuipFCMS -- 简单强大内容管理系统
    iWebShop -- 代替ecshop 的开源电子商务网站系统
    SuperSlide -- “焦点图/幻灯片”“Tab标签切换”“图片滚动”“无缝滚动”特效集成
  • 原文地址:https://www.cnblogs.com/wucg/p/3250143.html
Copyright © 2011-2022 走看看