开发者

linq-to-sql: Stored procedures cannot be used inside queries

This fails on VS2010 RC LINQ-to-SQL with the InvalidOperationException "Stored procedures cannot be used inside queries.":

var foo = (from a in aTable 
    from b in this.SomeStoredProced开发者_如何学JAVAure()
    where a.Id == b.Id
    select b.Id);

SomeStoredProcedure is a SQL procedure which returns a table. 'join' also appears to fail. Any thoughts why?


Because you can't call a stored procedure within a select statement.

Your command would look something like this in tsql... but this is not valid.

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

The LINQ statement would work if you were using a udf instead of a stored procedure. Alternatively, you could execute your stored procedure prior to doing the join.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜