linq-to-sql:存储过程不能在查询中使用 [英] linq-to-sql: Stored procedures cannot be used inside queries

查看:72
本文介绍了linq-to-sql:存储过程不能在查询中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这在带有InvalidOperationException的VS2010 RC LINQ-to-SQL上失败,在查询内不能使用存储过程.":

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.SomeStoredProcedure()
    where a.Id == b.Id
    select b.Id);

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

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

推荐答案

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

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

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

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

如果您使用udf而不是存储过程,则LINQ语句将起作用.另外,您可以在执行连接之前执行存储过程.

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);

这篇关于linq-to-sql:存储过程不能在查询中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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