为什么 linq 无法获取临时表值

发布于 2024-11-01 02:34:04 字数 504 浏览 0 评论 0原文

使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

指尖上得阳光 2024-11-08 02:34:04

我不认为这与临时表有任何关系,而是 Linq 不知道预期的输出是什么。

使用 Dotnet Framework 4,这很容易,因为您可以执行类似的操作

 (from r in ProviderName.TestProcedure().AsDynamic() 
       select new { r.Id, r.Description}).ToList()

(假设 Id 和描述是 DischargePort 中的字段),

否则,您需要在设计器中执行某些操作来告诉 Linq 您的过程输出什么。我从来没有这样做过,但也许 这篇文章会有所帮助。

当我想到这一点时,在这种特殊情况下,你应该能够做类似的事情

var results = (from r in ExecuteQuery<DischargePort>("exec TestProcedure") 
select  r ).ToList();

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

 (from r in ProviderName.TestProcedure().AsDynamic() 
       select new { r.Id, r.Description}).ToList()

(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

var results = (from r in ExecuteQuery<DischargePort>("exec TestProcedure") 
select  r ).ToList();
不乱于心 2024-11-08 02:34:04

我首先下载 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文