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

相关文章:

  • 2022-12-23
  • 2021-12-22
  • 2021-10-18
  • 2021-09-19
  • 2022-12-23
  • 2022-02-20
  • 2022-12-23
猜你喜欢
  • 2021-09-18
  • 2021-12-22
  • 2021-04-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案