Dapper returns the Stored Procedure Value

Source: Internet
Author: User

Using (IDbConnection conn = WebDbConn. DbService ()){
Conn. Execute (@"
Create proc # TestOutputParameterProc @ Foo int, @ Bar int out
Set @ Bar = @ Foo select 1 as [A] select 2 as [B] ");
Try
{
Var args = new DynamicParameters (new {Foo = 123 });
Args. Add ("@ Bar", dbType: DbType. Int32,
Direction: ParameterDirection. Output );
Using (var grids = conn. QueryMultiple ("# TestOutputParameterProc ",
Args, commandType: CommandType. StoredProcedure ))
{
// This will fail here; we have not consumed the TDS data yet!
// Args. Get <int> ("@ Bar"). isdue to (123 );

// Note we don't * have * to read the data here; disposing "grids"
// Wocould be enough to skip to the end of the TDS
// Var A = grids. Read <int> (). Single (). Equals (1); //
// Var B = grids. Read <int> (). Single (). Equals (2); // B
Var A = grids. Read <int> (). Single (); //
Var B = grids. Read <int> (). Single (); // B

}
// At this point we have consumed the TDS data, so the parameter
// Values have come back to the caller
Args. Get <int> ("@ Bar"). Equals (123 );
}
Finally
{// Clean up the proc
Conn. Execute ("drop proc # TestOutputParameterProc ");
}

 

Stored Procedure Return Value
Http://stackoverflow.com/questions/9870969/can-dapper-return-values-from-a-sql-function/9871380#9871380
Http://stackoverflow.com/questions/14723277/dapper-output-parameter-is-not-returning-values/14746522#14746522

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.