Sabir Hossain
Sabir Hossain

Reputation: 1205

Entity Framework Core take one and skip other duplicate item in a table

I have a table that contains a list of string and many item in the table have the same string with a different ID, Now I want to take all the items from the table but not more than one items with the same string.

Example Table

id    -   string
------------------
 1   ---   A 
 2   ---   B 
 3   ---   B 
 4   ---   C 
 5   ---   D 
 6   ---   D 
 7   ---   F

after the query the list should look like

A, B, C, D, F

How can I do that using LINQ?

Upvotes: 1

Views: 458

Answers (1)

Kevin
Kevin

Reputation: 4848

You could do something like this, I suppose:

var result = Context.yourTable.Select(t => t.fieldName).Distinct();

So, basically, your query is getting only distinct values for 'fieldName' (whatever that may be in your case).

Upvotes: 1

Related Questions