Can't use .Where or .Select with stored procedure call?
Options
When trying to use common LINQ methods such as .Where or .Select with a stored procedure call I get the error message "'LINQPad.ReturnDataSet' does not contain a definition for 'Where' and no extension method 'Where' accepting a first argument of type 'LINQPad.ReturnDataSet' could be found (press F4 to add a using directive or assembly reference)". The same LINQ command in C# itself works fine. The stored procedure apparently returns a DataSet with one DataTable in it but I don't have to do anything special to deal with that in C#. But LinqPad is a different story. What am I doing wrong?
Comments
-
I guess ReturnDataSet is a subtype of a DataSet. If you do (call to sp).Tables[0].AsEnumerable() you should then have access to the LINQ functions.
-
The easiest way to accomplish this is to call .AsDynamic() on the return data set:
spCustomers().AsDynamic().Where (x => x.Name.StartsWith ("T"))
AsDynamic is an extension method built into LINQPad that allows you to query the (untyped) output of stored procedures using dynamic typing.