开发者

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

  1. 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:

  1. Declared an internal / temp variable with type smallint
  2. Assigned the count value of the select statement to this variable
  3. Assigned the temp variable's value to my output parameter

This works!

Any further comments etc are welcome!!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜