c# - Linq to SQL,基于 If/Else 具有不同返回类型的存储过程

标签 c# linq-to-sql stored-procedures

我有一个现有的存储过程,我现在尝试使用 LINQ to SQL 调用它,这是存储过程:

ALTER procedure [dbo].[sp_SELECT_Security_ALL] (
@UID       Varchar(15)
)
as
DECLARE @A_ID   int

If ISNULL(@UID,'') = ''
    SELECT  DISTINCT
       App_ID,
       App_Name,
       App_Description,
       DB,
       DBNameApp_ID,
       For_One_EVA_List_Ind
    From      v_Security_ALL
ELSE
   BEGIN
        Select  @A_ID = (Select Assignee_ID From NEO.dbo.v_Assignees Where USER_ID = @UID and Inactive_Ind = 0)

    SELECT  DISTINCT
       Security_User_ID,
       Security_Company,
       Security_MailCode,
       Security_Last_Name,
       Security_First_Name,
       Security_User_Name,
       Security_User_Info,
       Security_User_CO_MC,
       Security_Email_Addr, 
       Security_Phone,
       Security_Security_Level, 
       Security_Security_Desc, 
       Security_Security_Comment,
       Security_Security_Inactive_Ind,
       App_ID,
       App_Name,
       App_Description,
       DB,
       DBNameApp_ID,
       For_One_EVA_List_Ind,
       @A_ID as Assignee_ID
    From      v_Security_ALL
    Where     Security_User_ID    = @UID
   END

我的问题是 intellsense 只能看到 IF 语句中的第一组返回值,而我无法从存储过程的“else”部分访问任何内容。所以当我尝试这样做时:

 var apps = dataContext.sp_SELECT_Security_ALL(userId);

        foreach (var app in apps)
        {
            string i = app.
        }

在应用程序上。我唯一可用的值是上面第一个 Select 不同的结果。

是否可以将 LINQ 与此类存储过程一起使用?

最佳答案

Scott Guthrie 已报道此案 in a blog post 。向下滚动到“处理存储过程中的多个结果形状。”

关于c# - Linq to SQL,基于 If/Else 具有不同返回类型的存储过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/284558/

相关文章:

c# - 搜索查询给出 LINQ to SQL 异常

c# - Linq to SQL 嵌套对象

sql-server - SQL Server 2000 : How to exit a stored procedure?

sql - 基于存储过程参数的条件 where 子句?

c# - 绑定(bind)到列表框时出现 XamlParseException

c# - 如何编写 C# 5 异步?

c# - 为什么要发生整数溢出?

linq-to-sql - SqlException,超时已到。超时时间在完成之前已过...我在哪里可以增加这个超时时间?

SQL Server - 存储过程突然变慢

c# - 在 SQLite 中为 WinRT 实现自定义排序规则