orm中使用存储过程

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

原文地址:https://www.cnblogs.com/redfull/p/6650711.html