Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linq/SQL Returning Different Results

Tags:

c#

sql

linq

I'm curious as to why my linq group by query returns 417 results whereas my SQL interpretation returns 419? I'm looking for duplicated emails from my list. I've checked out the result set and the two email addresses that are missing from the linq set both have accents. Does linq not recognize accents? Is there a workaround? The email field type is a nvarchar(100).

Let me know if you have any questions, Thanks in advance!

var listOfContacts = (from contacts in something
                      where contacts.Team.Id.Equals(TeamGuid) && !contacts.Email.Equals(null)
                      select new {contacts.Id, EmailAddress = contacts.Email.ToLower()}).ToList();

//Full Contact List; exact amount matches

var dupeEmailsList = listOfContacts
    .GroupBy(x => x.EmailAddress)
    .Where(g => g.Count() > 1)
    .Select(y => y.Key)
    .ToList();

//Returns 417
SELECT Email, COUNT(*)
FROM something
WHERE Team = 'Actual Team Guid Inserted Here'
GROUP BY Email
HAVING (COUNT(LOWER(Email)) > 1 AND Email IS NOT NULL)
ORDER BY Email

//Returns 419
like image 601
kpolewaczyk Avatar asked Jun 26 '26 12:06

kpolewaczyk


1 Answers

This is a known issue and the workaround has already been answered -> here and here

You have to explicitly tell it to ignore them.

like image 57
Bactos Avatar answered Jun 29 '26 04:06

Bactos