Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a bool or int result from a Stored Proc

I have a SP that returns a bit. This is how it's called from my C# program using EF context:

bool productCount = context.Database
                           .SqlQuery<bool>("EXEC [dbo].[SP_Name] @CatogeryID,@Id",
                            new SqlParameter("CatID", lngCatid),
                            new SqlParameter("SId", lngStudentId)
                           ).FirstOrDefault();

When the proc is run inside SQL MMS it gives correct result of True/False depending on the params.

The same proc always returns false when called.

What am I missing?

Any clues?

like image 337
Codehelp Avatar asked Dec 04 '25 05:12

Codehelp


1 Answers

Perhaps it's something in your stored proc not doing the select properly? Sample working code:

CREATE PROCEDURE [dbo].[testProc] 
    @inval bit output
AS
BEGIN
    declare @outval bit

    select @outval = @inval
    select @outval
END


using (var dbContext = new testContext())
{
    var data = dbContext.Database.SqlQuery<bool>("exec testProc {0}",false).FirstOrDefault();
    Console.WriteLine(data);
}
like image 185
Johan Danforth Avatar answered Dec 05 '25 19:12

Johan Danforth