I am trying to return a scalar value from a stored procedure. I actually want to return the ID of a newly created record, but I have simplified my problem down to a stored p
Thank you, DavidG for the article. It got me started down the right path. So what I did to solve this was change my Stored Procedure to return an ObjectResult
instead of an int
. Then I did a SingleOrDefault()
on the results of the Stored Procedure call, which yielded my int
return value. Like this:
Stored Proc:
-- RETURN @return does not work. Can't return a scalar value
SELECT @return -- This returns a result set with a single object that contains an int.
Then, my generated code looks like above but instead of returning an int
it returns an ObjectResult
and I read the results like this:
var id = myDbContext.My_Return_Int(123).SingleOrDefault();