首页 > 其他 > 详细

orm中使用存储过程

时间:2017-03-31 12:59:59      阅读:262      评论:0      收藏:0      [点我收藏+]

在orm开发中也会用到存储过程,案例如下:

Create proc [dbo].[proc_GetCompanyStructureByDepartStructureId] @Com_StructureId uniqueidentifier
AS
BEGIN
declare @structureType int
declare @parentStructureId uniqueidentifier
select @structureType=b.Type,@parentStructureId=a.ParentStructureID from Com_Structure a inner join Com_StructureType b
on a.Com_SructureTypeID=b.Com_StructureTypeID where Com_StructureID=@Com_StructureId

if(@structureType=2)--2表示部门
select Top 1 * from Com_Structure where Com_StructureID=@parentStructureId
END

GO

sql中直接调用存储过程  exec proc_GetCompanyStructureByDepartStructureId ‘47F10D40-535A-4AF8-AD98-81616A2822B1‘

orm调用存储过程 如下:

Guid CompanyStructureId;
var dr = McDB.DBContext.StoredProcedure("proc_GetCompanyStructureByDepartStructureId").AddInputParameter("@Com_StructureId", System.Data.DbType.Guid, id).ToDataReader();
while (dr.Read())
{
CompanyStructureId = Guid.Parse(dr["Com_StructureId"].ToString()); //存储过程返回一条记录,取其中的单个值
}
dr.Close();

orm中使用存储过程

原文:http://www.cnblogs.com/redfull/p/6650711.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!