Is it Possible to call a Stored Procedure using LINQ in LINQPad?

Summing up some of the other answers as well as adding a bit of additional information:

Connect to your data source using the Default (LINQ to SQL) driver. Make sure that the check box Include Stored Procedures and Functions is checked.

Stored procedures and functions are now available as .NET functions (e.g. C#) in queries using the connection. The parameters required by the function reflects the parameters required by the stored procedure or database function.

The value returned by the function is a ReturnDataSet which is a LINQPad type deriving from DataSet. Unfortunately it is not so easy to perform LINQ queries on data sets but LINQPad provides the extension method AsDynamic() that will take the first table of the returned data set (normally there is only one table) and convert the rows to IEnumerable<Object> where the objects in the collection are dynamic allowing you to access the column values as properties. E.g. if your stored procedure returns columns Id and Name you can use LINQ:

SomeStoredProc().AsDynamic().Where(row => row.Id == 123 && row.Name == "Foo")

Unfortunately you will not have intellisense because the row objects are dynamic.


At least in my copy of LINQPad, stored procedures show up in the database treeview and can be invoked directly.

Here's a screenshot:

Screenshot


My Answer (With Daniel's assistance, thanks.)

Daniel helped me realize that stored procedures can be called if you target a database with the drop down list in the query window; then in the query window call the stored proc by its name and append parentheses to the end to call it as a function.

The main difference between the current version (I'm using 4.26.2 as of this date) is that LINQ in VS returns custom data types to match data objects returned from the stored procedure and LINQPad returns a DataSet. So by selecting "C# Statement(s)" you can successfully run this as a query:

DataSet fooResults = foo_stored_proc(myParam);

Thanks for everyone's help!


Example: Say I have a Stored Procedure called PersonMatchNoDOBRequired and it expects me to pass in a First and Last Name

var b = PersonMatchNoDOBRequired("John", "Smith").AsDynamic();
b.Dump();

If I want further filtering ( in my case I have an advanced algorithm in sql that scores the first and last name , first name can return "Jodi" , but say I really want to filter it further then it is like this:

var b = PersonMatchNoDOBRequired("John", "Smith").AsDynamic().Where(x => x.FirstName == "John" && x.LastName == "Smith");   

Other answers are partially right - I didn't see anything passing in the parameters ( if needed).