0 votes
1 view
in SQL by (22.4k points)

I am trying to use .distinct in Linq to get the result based on one field of the table (so do not require whole duplicated records from the table).

I know writing a basic query using distinct as followed:

var query = (from r in table1

orderby r.Text

select r).distinct();

but I need results where r.text is not duplicated.

1 Answer

0 votes
by (40.3k points)

Try using the code given below:

table1.GroupBy(x => x.Text).Select(x => x.FirstOrDefault());

This will help to group the table by Text and use the first row from each group resulting in rows where Text is distinct.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...