I am trying to access the return value of a stored procedure with Linq
DECLARE @ValidToken int = 0 //I have also tried using a bit instead of an int here.
IF EXISTS(SELECT 1 FROM Tests WHERE TestToken = @Token)
select @ValidToken = 1
return @ValidToken
This works when running the SP through sql studio. However I am trying to run it with linq using the datacontext class and it is always returning -1.
using (DataEntities dataEntities = new DataEntities())
{
int query = data.ValidateToken(id);
Response.Write(query.ToString());
}
query will always equal -1 and I am not sure why.
I have looked online and it would appear that there are easier ways to get the return value however I would rather stick to Linq as that is what the rest of the program is using.
Why are you all using a stored procedure as function?
Though a stored procedure has return
, it is not a function, so you should not use return
to return data,
Rather, you should use Output parameters and other ways to return data, as documented at MSDN
And the use of return
is documented at MSDN
misusing return
is probably the reason why LINQ does not understand your stored procedures.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With