【问题标题】:linq-to-sql: Stored procedures cannot be used inside querieslinq-to-sql:不能在查询中使用存储过程
【发布时间】:2010-03-02 01:38:14
【问题描述】:

这在 VS2010 RC LINQ-to-SQL 上失败,并出现 InvalidOperationException“存储过程不能在查询中使用。”:

var foo = (from a in aTable 
    from b in this.SomeStoredProcedure()
    where a.Id == b.Id
    select b.Id);

SomeStoredProcedure 是一个返回表的 SQL 过程。 “加入”似乎也失败了。有什么想法吗?

【问题讨论】:

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


    【解决方案1】:

    因为您不能在 select 语句中调用存储过程。

    您的命令在 tsql 中看起来像这样...但这是无效的。

    select b.Id
        from aTable a
        inner join (exec SomeStoredProcedure) b on a.Id = b.Id
    

    如果您使用 udf 而不是存储过程,则 LINQ 语句将起作用。或者,您可以在加入之前执行您的存储过程。

    var foo = (from a in aTable 
        from b in this.SomeStoredProcedure().ToList()
        where a.Id == b.Id
        select b.Id);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-14
      相关资源
      最近更新 更多