calling stored procedure with linq
I am new to Linq server开发者_开发百科. I have a stored procedure in my databse that retuens count number.
select COUNT(*) from tbl_WorkerUsers
where WorkerCode=@Wcode
when I run it directly in my database it returns 1.
exec checkWorkerCodeAvailibility 100000312
but when I run it in c# code it always returns null.
WorkerDataContext Wkc = new WorkerDataContext();
int? result = Wkc.checkWorkerCodeAvailibility(Int32.Parse(Wcode)).Single().Column1;
what's wrong?
Define your Stored Procedure like this:
CREATE PROCEDURE [dbo].[checkWorkerCodeAvailibility]
@Wcode int = 0
AS
BEGIN
SET NOCOUNT ON;
DECLARE @Result INT
SELECT @Result = COUNT(*) FROM tbl_WorkerUsers WHERE WorkerCode=@Wcode
RETURN @Result
END
You can then access this using the following code:
int result = db.checkWorkerCodeAvailibility(Int32.Parse(WCode));
精彩评论