LINQPAD - Using Stored Procedures / Accessing a DataSet

by 10. September 2008 10:45

LINQPAD has quickly become my best friend - I think it is inevitable that everyone, like myself, will need to work with stored procedures.  In my case I have Linked Servers that I want to access from a single database and have configured a stored procedure to return me the data I need from the applicable Server(s) / Table(s).

The question when I left work today was - how do I make LINQPAD work with Stored Procedures?  All my efforts failed as shown below:

Prior to the above error I was getting a DataSet message (I hoped DataTable might have more success).  The only thing I could get to work was the following, very basic, command:

When I got home my research resumed and I stumbled upon the following link:

It had exactly what I was looking for:

Language-Integrated Query (LINQ) queries work on data sources that implement the IEnumerable<(Of <(T>)>) interface or the IQueryable interface. The DataTable class does not implement either interface, so you must call the AsEnumerable method to use the DataTable as a source in the From clause of a LINQ query. You can also obtain custom, domain-specific operators, such as CopyToDataTable, by returning an IEnumerable<(Of <(T>)>) object.

However I quickly ran into the following response when I added AsEnumerable() to the query:


A little more research led me to this link which suggested (once again) that this should be working... which has the following content:


It was when I drilled down into the AsEnumerable() method that I realized that it was an Extension!  The LINQPAD message, "press F4 to add a using directive..." had me very hopeful.  I hit F4 and added the System.Data.DataSetExtensions.dll


Walla! I'm using a Stored Procedure within LINQPAD!

I strongly recommend that you buy the book - I got mine in yesterday and the quality and usefulness of the content matches the LINQPAD application.

Tags: , ,


Blog videos and references to CodePlex projects are no longer valid