转: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();
}
转:NHibernate 存储过程的更多相关文章
- [NHibernate]存储过程的使用(二)
目录 写在前面 文档与系列文章 创建对象 更新对象 总结 写在前面 上篇文章介绍了如何使用MyGeneration代码生成器生成存储过程,以及nhibernate中通过存储过程删除数据的内容,这篇文章 ...
- [NHibernate]存储过程的使用(三)
目录 写在前面 文档与系列文章 查询 总结 写在前面 前面的文章介绍了在nhibernate中使用存储过程进行增删改的操作,当然查询也是可以的,在nhibernate中也可以执行任意的存储过程.本篇文 ...
- [NHibernate]存储过程的使用(一)
目录 写在前面 文档与系列文章 Nhibernate中使用存储过程 一个例子 总结 写在前面 上篇文章一个小插曲,分析了延迟加载是如何解决N+1 select查询问题的.这篇开始介绍在nhiberna ...
- NHibernate 存储过程使用
NHibernate也是能够操作存储过程的,不过第一次配置可能会碰到很多错误. 一.删除 首先,我们新建一个存储过程如下: CREATE PROC DeletePerson @Id int AS DE ...
- Nhibernate 存储过程获取返回值
写在前面:因为项目使用ssh.net所以做着做着要调用存储过程,而且是有返回值的,按照以前的做法直接在参数里指定下就可以获取,但是在nhibernate里调用就有点陌生了,百度一下得出的结果有两种:第 ...
- NHibernate 存储过程 第十四篇
NHibernate也是能够操作存储过程的,不过第一次配置可能会碰到很多错误. 一.删除 首先,我们新建一个存储过程如下: CREATE PROC DeletePerson @Id int AS DE ...
- [Nhibernate]SchemaExport工具的使用(二)——创建表及其约束、存储过程、视图
目录 写在前面 文档与系列文章 表及其约束 存储过程 视图 总结 写在前面 由于一直在山西出差,有几天没更新博客了.昨晚回到家,将博客园最近三天更新的文章搜集了一下,花费了半天的时间,看了看,有些文章 ...
- 耗时两月,NHibernate系列出炉
写在前面 这篇总结本来是昨天要写的,可昨天大学班长来视察工作,多喝了点,回来就倒头就睡了,也就把这篇总结的文章拖到了今天. nhibernate系列从开始着手写,到现在前后耗费大概两个月的时间,通过总 ...
- [NHibernate]代码生成器的使用
目录 写在前面 文档与系列文章 代码生成器的使用 总结 写在前面 前面的文章介绍了nhibernate的相关知识,都是自己手敲的代码,有时候显得特别的麻烦,比如你必须编写持久化类,映射文件等等,举得例 ...
随机推荐
- [BZOJ2876]骑行川藏
以前并没有发现微积分教材上有这种东西...我还是太菜了... 其实就是要在满足$\sum\limits_{i=1}^nk_is_i(v_i-v_i')^2\leq E$的同时求$\sum\limits ...
- 【差分约束系统】【spfa】UVALive - 4885 - Task
差分约束系统讲解看这里:http://blog.csdn.net/xuezhongfenfei/article/details/8685313 模板题,不多说.要注意的一点是!!!对于带有within ...
- 求满足n^2>12000的n的最大值 Exercise05_13
/** * @author 冰樱梦 * 时间:2018年下半年 * 题目:求满足n^2>12000的n的最大值 * */ public class Exercise05_13 { public ...
- 【R笔记】glm函数报错原因及解析
R语言glm函数学习: [转载时请注明来源]:http://www.cnblogs.com/runner-ljt/ Ljt 作为一个初学者,水平有限,欢迎交流指正. glm函数介绍: glm(for ...
- 使用MultipleInputs和MultipleOutputs
还是计算矩阵的乘积,待计算的表达式如下: S=F*[B+mu(u+s+b+d)] 其中,矩阵B.u.s.d分别存放在名称对应的SequenceFile文件中. 1)我们想分别读取这些文件(放在不同的文 ...
- python 使用mysql示例
安装MySQL驱动 由于MySQL服务器以独立的进程运行,并通过网络对外服务,所以,需要支持Python的MySQL驱动来连接到MySQL服务器.MySQL官方提供了mysql-connector-p ...
- JavaScript之链式结构序列化1
一.概述 在JavaScript中,链式模式代码,太多太多,如下: if_else: if(...){ //TODO }else if(...){ //TODO }else{ //TODO } swi ...
- iOS -- 解决iOS11中navigationBar上使用initWithCustomView按钮图片错位 frame无效
在iOS11上当使用如下代码设置时 UIButton *shareButton = [UIButton buttonWithType:(UIButtonTypeCustom)]; shareButto ...
- [转载]Oracle批量执行
FROM: http://www.cnblogs.com/wangyayun/p/4514411.html //批量添加20000条数据用时8秒. try { String url = "j ...
- asp.net购物车,订单以及模拟支付宝支付(一)---购物车表及添加购物车流程
在开发一个Web程序的时候用到了网购这个功能,上来分享并记录一下,以便以后忘记了可以自己看看(电脑东西太多,笔记都不知道放哪里去了啊啊啊啊啊!!!) 没有什么高并发量,什么什么技术理论,只是一个最最基 ...