调用LINQ的存储过程 [英] calling stored procedure with linq

查看:98
本文介绍了调用LINQ的存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的LINQ服务器。
我有我的DATABSE计数retuens数量的存储过程。

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

当我直视着我的数据库中运行它,它返回1。

when I run it directly in my database it returns 1.

    exec checkWorkerCodeAvailibility 100000312

但是当我在C#$ C $运行c那么它总是返回null。

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;

什么是错的?

推荐答案

定义你的存储过程是这样的:

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

您可以然后使用以下code访问此:

You can then access this using the following code:

int result = db.checkWorkerCodeAvailibility(Int32.Parse(WCode));

这篇关于调用LINQ的存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆