开发者

Why linq fail to get temp table values

开发者 https://www.devze.com 2023-02-24 23:49 出处:网络
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:

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开发者_JAVA技巧 [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.


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


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.

0

精彩评论

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

关注公众号