Reputation:
How do you use LINQ (C#) to select the value in a particular column for a particular row in a datatable. The equivalent SQL would be:
select Distinct page_no from pagetable;
Thanks in advance.
Upvotes: 0
Views: 446
Reputation: 34846
There is also the MoreLINQ project, which adds some of the methods that should have been a part of LINQ to Objects in the first place.
Upvotes: 0
Reputation: 45083
You can use a combination of Select
and Distinct
:
var distinctThings = things.Select(i => i.Property).Distinct();
Upvotes: 0
Reputation: 125630
var items = source.Select(x => x.Property).Distinct();
or for DataTable
:
var items = dt.AsEnumerable().Select(x => x.Field<string>("columnName")).Distinct();
Upvotes: 0
Reputation: 26737
var result = YourContext.pagetable.Select(x => x.page_no).Distinct()
Upvotes: 3