linq-to-sql:存储过程不能在查询中使用

时间:2010-03-02 01:38:14

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

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

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

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

1 个答案:

答案 0 :(得分:2)

因为您无法在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);