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();
}

最新文章

  1. [django]从前端返回字符串,后端转换为字典,执行数据添加操作
  2. struts2学习笔记之五:表单数据收集的几种方式
  3. CSS3入门之转换
  4. How to use the Isolated Storage Explorer tool for Windows Phone
  5. C#基础--之数据类型
  6. HTML前端--各种小案例
  7. DNA Sorting 分类: POJ 2015-06-23 20:24 9人阅读 评论(0) 收藏
  8. js键盘操作事件
  9. phpstom 实用laravel 需要附加的 命令
  10. Spring-----5、Spring容器中的bean
  11. elasticsearch集群部署
  12. Java8 HashMap之tableSizeFor
  13. [SinGuLaRiTy] 平衡树
  14. tomca配置文件自动还原问题的解决 server.xml content.xml 等
  15. hdu 1880 魔咒字典
  16. AngularJS学习笔记之directive——scope选项与绑定策略
  17. Arrays工具、二维数组以及LeetCode练习题
  18. MongoDB监控(常见监控方法及profile)-temp
  19. Unity3D编辑器扩展(五)——常用特性(Attribute)以及Selection类
  20. 1085 Perfect Sequence (25 分)

热门文章

  1. 【OpenStack Cinder】Cinder安装时遇到的一些坑
  2. 【点分治】【乘法逆元】hdu4812 D Tree
  3. 十. 图形界面(GUI)设计5.布局设计
  4. 可见性-volatile
  5. C# 6.0语法新特性体验(二)
  6. html5:localStorage储存
  7. LVM分区管理和扩展
  8. RenderMonkey基本使用方法【转】
  9. unity render pipeline
  10. Highcharts、AJAX、JSON、JQuery实现动态数据交互显示图表柱形图