Entity Framework chooses a unique name

c# distinct entity-framework linq

Question

How can I do this SQL query with Entity Framework?

SELECT DISTINCT NAME FROM TestAddresses
1
131
8/16/2019 8:07:04 PM

Accepted Answer

Using lambda expression..

 var result = EFContext.TestAddresses.Select(m => m.Name).Distinct();
259
12/27/2010 3:36:19 PM

Popular Answer

Try this:

var results = (from ta in context.TestAddresses
               select ta.Name).Distinct();

This will give you an IEnumerable<string> - you can call .ToList() on it to get a List<string>.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow