Stored Procedure return values with linq data context
c#, linq, sql, sql-server, stored-procedures
Solution
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.
Problem
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.