为什么 linq 无法获取临时表值
使用C# vs2008。我有一个存储过程,这个过程保存临时表,我需要获取临时表值。我的sql查询如下:
create procedure [dbo].[TestProcedure]
as
SELECT * INTO #temp1 from(select * from DischargePort) as b
select * from #temp1
drop table #temp1
我上面的查询有一个名为#temp1的临时表。在sql-server-management中运行此查询后,我得到结果,但是当我尝试在 linq 中执行这个过程时,我没有得到任何结果。我的 linq 语法如下:
var r = ProviderName.TestProcedure();
任何人都可以告诉我为什么会出现这个问题,如何克服这个问题。希望任何人不要说 linq 无法处理临时表或此类单词。如果有任何疑问,请询问。提前致谢。
work on C# vs2008. I have a stored procedure ,This procedure holds temp table ,i need to get the temp table values.My sql query is bellow:
create procedure [dbo].[TestProcedure]
as
SELECT * INTO #temp1 from(select * from DischargePort) as b
select * from #temp1
drop table #temp1
My above query has a temp table named #temp1.After run this query in sql-server-management i get result ,but when i try to execute this procedure in linq ,I get no result.My linq syntax is bellow:
var r = ProviderName.TestProcedure();
Can anybody tell me why this problem arise,How to overcome this problem.Hope any body not say that linq can not handled the temp table or this kind of word.if have any query plz ask .Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不认为这与临时表有任何关系,而是 Linq 不知道预期的输出是什么。
使用 Dotnet Framework 4,这很容易,因为您可以执行类似的操作
(假设 Id 和描述是 DischargePort 中的字段),
否则,您需要在设计器中执行某些操作来告诉 Linq 您的过程输出什么。我从来没有这样做过,但也许 这篇文章会有所帮助。
当我想到这一点时,在这种特殊情况下,你应该能够做类似的事情
I don't think this is anything to do with the temporary table, but rather that Linq does not know what output is to expected.
With Dotnet Framework 4, this is easy, as you can do something like
(assumes Id and description are fields in DischargePort)
Otherwise, you need to do something in your designer to tell Linq what your procedure outputs. I have never had to do this, but perhaps this article will help.
When I think about it, in this particular case, you should be able to do something like
我首先下载 linqpad 来查看 linq 发出的 sql,这可能会提供一些线索。您还可以使用 sql profiler 工具来查看正在运行的查询。
i would start by downloading linqpad to see the sql that linq is emitting, this may provide some clues. you could also use the sql profiler tool to see what query is being run.