0

I know how to do this in T-SQL - it's easy.

How can I do this in EF using C# ?

SELECT
    name, email, COUNT(*)
FROM
    users
GROUP BY
    name, email
HAVING 
    COUNT(*) > 1

What is the Entity Framework equivalent to this?

The question that is marked as a duplicate is not an answer to this question. Maybe the person who marked it as a duplicate doesn't understand EF or T-SQL.

Yusha
  • 1,066
  • 2
  • 10
  • 26
  • 1
    This has nothing to do with my question. Question is not a duplicate – Yusha Apr 12 '19 at 20:50
  • 3
    Should be something like `users.GroupBy( u => new { u.Name, u.Email } ).Where( g => g.Count() > 1 ).Select( g => new { Name = g.Key.Name, Email = g.Key.Email, Count = g.Count() )`. Report back if this works. – Wiktor Zychla Apr 12 '19 at 20:51
  • Nothing to do with your question? It's almost identical! If that's not a duplicate all duplicates at Stack Overflow are false. – Gert Arnold Apr 12 '19 at 22:24
  • You just said "It's *almost* identical"....... – Yusha Apr 15 '19 at 13:46
  • The duplicate does not answer my question... Please don't mark as duplicate unless you actually understand the questions. Thanks. – Yusha Apr 15 '19 at 14:01
  • The duplicate is asking how to do a EF equivalent with a JOIN. I'm not talking about a join NOR am i looking for LINQ-QUERY syntax... – Yusha Apr 15 '19 at 14:24
  • @WiktorZychla I am trying your solution now, thanks. – Yusha Apr 15 '19 at 14:26
  • @WiktorZychla It worked. Thanks – Yusha Apr 15 '19 at 14:53
  • The duplicate asks "How can I write a linq to entities query that includes a having clause?". The join is a minor difference. You should be able to tune out such small differences and focus on the essentials when searching for answers on the web. You can't expect a question like this not to have been asked before and you should have been able to find the answer without posting a new question. – Gert Arnold Apr 18 '19 at 09:47

0 Answers0