C# 3.0 in a Nutshell
C# 3.0 in a Nutshell, Third Edition A Desktop Quick Reference

By Joseph Albahari, Ben Albahari
Price: $49.99 USD
£30.99 GBP

Cover | Table of Contents | Forum


Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
Linqpad And Datasets, Trying to requery a stored procedures results
Richard
post Apr 19 2008, 01:48 PM
Post #1


New Member
*

Group: Members
Posts: 1
Joined: 19-April 08
Member No.: 238



Hi,

We use DataSets within one of our applications and I'm trying to use LINQPad to model re-querrying of their data. I've set-up the original query as a stored procedure which loads an example of the data which would populate the DataSet, then I try to re-query it.

I'm running this in C# statements mode: -


var results = ExampleCrossTab();

var results2 =
from dr in results
where (dr.OptionId == 788)
group dr by dr.TransactionId into transactionGrouping
select new
{
transactionGrouping.Key,
TransactionCount = transactionGrouping.Count(),
TransactionList = (from dr2 in transactionGrouping select dr2).ToArray()
};

Requesting the contents of ExampleCrossTab() on it's own works fine but when querried like the above I keep getting the error: -

"Could not fine implementation of the query pattern for source type 'System.Data.DataSet'. 'Where' not found."

In Visual Studio this works fine. Does anyone know what is happening and how I can requery the result using LINQPad?


Thanks
Richard
Go to the top of the page
 
+Quote Post
Joseph Albahari
post Apr 20 2008, 02:06 AM
Post #2


Active Member
**

Group: Members
Posts: 20
Joined: 16-February 08
Member No.: 90



Hi Richard

LINQPad returns the results of stored procedures as untyped DataSets. In this regard, it differs from Visual Studio's LINQ to SQL Designer, which returns the results in structured entities. On the positive side, it means that you see the full output of stored procedures that return multiple result sets. On the negative side, you can't then perform LINQ queries over the results returned.

A workaround is to use table-valued functions instead of stored procedures. In LINQPad, these return structured result sets upon which you can run LINQ queries.

In your case, I strongly suggest you change ExampleCrossTab to a table-value function anyway - because it means queries such as the own you quoted will execute on the server instead of the client. This is much more efficient - you'll only fetch the result with the Option ID of 788 back to the client rather than fetching the entire result set and then querying locally.

Regards

Joe
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

RSS Lo-Fi Version Time is now: 16th May 2008 - 11:07 AM