开发者

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

开发者 https://www.devze.com 2022-12-14 17:08 出处:网络
Using Oracle® Data Provider for .NET to generate strongly typed datasets. I could of开发者_StackOverflow course fill the entire table, but I would like to learn how to use the Where() extension with

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

I could of开发者_StackOverflow 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));


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);


In C# a lambda expression is typically used as the function. I.E.:

tableAdapter.Fill(myDataSet.CUSTOMER.Where(c => c.LastName == "Smith"));
0

精彩评论

暂无评论...
验证码 换一张
取 消