使用Dapper在C#中返回多个输出并返回图像值 [英] Return Multiple Out and Return Image value in C# using Dapper
本文介绍了使用Dapper在C#中返回多个输出并返回图像值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用C#中的Dapper从存储过程中返回图像?
How to return image from Stored procedure using Dapper in C#?
我有一个存储过程,其中包含多个out和一个返回值。我想在C#中读取返回类型
I have a stored procedure with multiple out's and a return value. I want to read the return type in C#
PFB代码和存储过程。请建议我如何解决此问题。
PFB the Code and Stored procedure. Please suggest me how to resolve this.
CREATE PROCEDURE procedure_Sessions
@id nvarchar(80),
@IsLocked bit OUTPUT,
@LockAge int OUTPUT
AS
DECLARE @textptr AS varbinary(16)
DECLARE @length AS int
DECLARE @now AS datetime
SET @now = GETUTCDATE()
-- Update Query Begins not complete Query example --
@textptr = CASE IsLocked
WHEN 0 THEN TEXTPTR(State)
ELSE NULL
END
@length = CASE IsLocked
WHEN 0 THEN DATALENGTH(State)
ELSE NULL
END
-- Update Query Ends--
IF @length IS NOT NULL BEGIN
READTEXT dbo.commons.State @textptr 0 @length
END
RETURN 0
C#代码:
DynamicParameters dp = new DynamicParameters();
dp.Add("@Id", Id);
dp.Add("@IsLocked", dbType: DbType.Boolean, direction: ParameterDirection.Output);
dp.Add("@LockAge", dbType: DbType.Int32, direction: ParameterDirection.Output);
dp.Add("ReturnValue", dbType: DbType.Object, direction: ParameterDirection.ReturnValue);
connection.Query<byte>("Exclusive", dp, commandType: CommandType.StoredProcedure);
isLocked = dp.Get<bool>("@IsLocked");
lockAge = dp.Get<int>("@LockAge");
var returnvalue = dp.Get<object>("ReturnValue");
推荐答案
https://www.learndapper.com/relationships
public async Task<List<ResultClass>> Load()
{
try
{
var query = "SELECT * from procedure_Sessions";
var result = await Db.QueryMultipleAsync(query).ConfigureAwait(false);
return result.Read<ResultClass>().ToList();
}
catch (Exception exception)
{
Console.WriteLine();
throw;
}
}
这篇关于使用Dapper在C#中返回多个输出并返回图像值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文