Search code examples
c#.netoracleodp.net

Help for extension Where() (this IEnumerable<CUSTOMERRow> source, Func<CUSTOMERRow, bool> predicate)


Using Oracle® Data Provider for .NET to generate strongly typed datasets.

I could of course fill the entire table, but I would like to learn how to use the Where() extension with a delegate function that should limit number of collected rows based on certain table values.

Parameters for Where() extension:

(this IEnumerable<CUSTOMERRow> source, Func<CUSTOMERRow, bool> predicate)

The codesnippet where the delegate should be used:

StronglyTypedDataSet myDataSet = new StronglyTypedDataSet();

CUSTOMERTableAdapter tableAdapter = new CUSTOMERTableAdapter();
tableAdapter.Fill(myDataSet.CUSTOMER.Where(newfunctionhere));

Solution

  • The Where method can be used to filter the contents of a collection. But in your case you're using a table adapter to fill an empty DataTable, and calling Where on an empty collection just yields an empty sequence... And the table adapter doesn't know how to interpret the Where call, it just uses its SelectCommand to fill the table. So you can't use Linq to define which data you want to load in the table. But once your table is filled, then you can use Where to filter the results, like that :

    var rows = myDataSet.CUSTOMER.AsEnumerable().Where(cr => cr.SomeProperty == someValue);