Output Parameter With Linq
I am new to and getting used to LINQ. I have worked with SPROCS that return result sets. No problems there.
However I am having a problem with OUTPUT params & LINQ.
the stored procedure i simple enough
CREATE PROCEDURE [dbo].[PROCNAME]
-- Add the parameters for the
stored procedure here
@tcStageOccurrences smallint output
SELECT @tcStageOccurrences =
isnull(COUNT(*),0) from
Stage where Condition
I am calling this in C# as follows
System.Nullable<Int16> tcStageOccurences = null;
MyDb.ProcName(ref @tcStageOccurrences);
The value of @tcStageOccurrences is 0 whereas it should be >0
Questions
- I have always used SQLparam & ExcuteReader or ExecuteNonQuery without any problems. Since I am trying to do the same thing in LINQ, is there something I am missing out?
I know that i can and proba开发者_StackOverflow社区bly should be using a scalar function instead.
But in some cases there are multiple OUTPUT parameters that I need to access within C#
Any help or useful tips are most welcome :-)
Regards
I have got the answer to this after thinking this one over and well it involved some experimenting as well.
This is what i did:
- Declared an internal / temp variable with type
smallint
- Assigned the count value of the select statement to this variable
- Assigned the temp variable's value to my output parameter
This works!
Any further comments etc are welcome!!
精彩评论