user2531795
user2531795

Reputation:

Linq distinct equivalent

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

Answers (4)

Karl Anderson
Karl Anderson

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

Grant Thomas
Grant Thomas

Reputation: 45083

You can use a combination of Select and Distinct:

var distinctThings = things.Select(i => i.Property).Distinct();

Upvotes: 0

MarcinJuraszek
MarcinJuraszek

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

Massimiliano Peluso
Massimiliano Peluso

Reputation: 26737

var result = YourContext.pagetable.Select(x => x.page_no).Distinct()

Upvotes: 3

Related Questions