I'm using C# / Entity Framework and trying to use Distinct()
with just one property, but I could not find the correct syntax.
What I have:
context
.Orders
.Select(o => o.User)
.Distinct();
The final query is doing a distinct with the entire User object:
SELECT
[Distinct1].[ID] AS [ID],
[Distinct1].[Name] AS [Name],
[Distinct1].[Email] AS [Email],
(...)
What I need is to distinct just using one property, like Name. The final query would be something like:
SELECT
[ID],
[Distinct1].[Name] AS [Name],
[Email],
(...)
If I use ToList()
before Distinct()
, I can use a EqualityComparer
inside Distinct()
, but I'm trying to avoid it since I'm having performance issues, since it is loading a high load of information into memory instead of filtering in the database.