0

I have to join results from 2 sprocs in LINQ but got the error message: 'System.Data.DataSet' does not contain a definition for 'Where' and no extension method 'Where' accepting a first argument of type 'System.Data.DataSet' could be found (press F4 to add a using directive or assembly reference)

However after added the DataSetExtensions the error still appears.

Code:

var c = GetAllGameCategories (123);
var d = GetGameCategories(22458);

Var e = c.Where(....);  // Error on this line!

Any help appreciated.

Chris
  • 657
  • 1
  • 9
  • 17
  • have a look at this http://stackoverflow.com/questions/10855/linq-query-on-a-datatable – Simon Fox Sep 06 '10 at 02:19
  • Got 'System.Data.DataSet' does not contain a definition for 'AsEnumerable' and the best extension method overload 'System.Data.DataTableExtensions.AsEnumerable(System.Data.DataTable)' has some invalid arguments – Chris Sep 06 '10 at 02:39
  • Am I suppose to find way to cast or convert result set of sproc query into DataTable as always? – Chris Sep 06 '10 at 02:41
  • the DataSet is a collection of DataTables, you must choose which table you want to query. You can get a DataTable from a DataSet using the index operator on the Tables collection i.e. myDataSet.Tables[0] – Simon Fox Sep 06 '10 at 02:43

1 Answers1

0

A DataSet is a collection of DataTable objects.
It does not directly contain any data.

You need to call .Where() on the DataTable.
EDIT: If it isn't a typed DataTable, you'll need to call .AsEnumerable() first.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • Thanks SLaks, appreciated for your help. – Chris Sep 06 '10 at 03:15
  • The result is from SPROC query, sorry I didn't explicitly state what exactly the type it is, but from LINQPad I got the impression that its treated as DataSet by default. I was using LINQPad to test out my lambdas but at the end I use the .ToArray() to both c and d back in the code as a work around. – Chris Sep 06 '10 at 03:18
  • foreach (var item in c) { foreach (var item2 in d) { if (item.ID == item2.ID) { return item.ShortDescription.ToString(); } } } // Return a null string if match failed. return null; – Chris Sep 06 '10 at 03:19