How to Select Distinct with aggregate columns in Entity Framework with LINQ?
-
Say I have a userTable and an orderTable. the criteria for the usertable is such that I WILL get the same user more than once How do I do a DISTINCT and a SUM(...) in Linq? In SQL it is : SELECT DISTINCT u.Name, u.Phone, SUM(o.Amount) FROM User u JOIN Order o ON u.UserId = o.UserId WHERE u.Type = 1 OR u.External = 1 GROUP BY Name, Phone TIA... -- Dag
-
Say I have a userTable and an orderTable. the criteria for the usertable is such that I WILL get the same user more than once How do I do a DISTINCT and a SUM(...) in Linq? In SQL it is : SELECT DISTINCT u.Name, u.Phone, SUM(o.Amount) FROM User u JOIN Order o ON u.UserId = o.UserId WHERE u.Type = 1 OR u.External = 1 GROUP BY Name, Phone TIA... -- Dag
Use SQL To Linq of LinqPad to convert your sql queries to Linq. Below are the link: Linqer | SQL to LINQ converter[^] LINQPad - The .NET Programmer's Playground[^]
Life is a computer program and everyone is the programmer of his own life.