1

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.

3
  • Do you get the result if you remove the drop statement and refresh the TestProvider metadata in the designer? Apr 13, 2011 at 4:59
  • What type do you expect r to be and what are you doing with it?
    – sgmoore
    Apr 13, 2011 at 8:54
  • asp316-after remove the drop table #temp1 from the procedure ,I don't get the result.
    – shamim
    Apr 17, 2011 at 5:35

2 Answers 2

1

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

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.