I am trying to group a list of common objects by the Email property but I am not getting the results I'm expecting.
var users = new List<Profile>
{
new SharePointProfile
{
Id = 1,
LoginName = "Login1",
Title = "Login1 SharePoint",
Email = "Login1@sharepoint.com",
IsSiteAdmin = false
},
new SharePointProfile
{
Id = 2,
LoginName = "Login2",
Title = "Login2 SharePoint",
Email = "Login2@sharepoint.com",
IsSiteAdmin = true
},
new Auth0Profile
{
Email = "Login2@sharepoint.com",
Name = "Login2 SharePoint Auth0"
},
new Auth0Profile
{
Email = "test@test.com",
Name = "Test User Auth0"
}
};
var userGroups = users.GroupBy(m => m.Email)
I am expecting to see three groups:
- Group #1 - Login1@sharepoint.com - 1 SharePointProfile object
- Group #2 - Login2@sharepoint.com - 1 SharePointProfile object and 1 Auth0Profile object
- Group #3 - test@test.com - 1 Auth0Profile object
What am I doing wrong here?
public abstract class Profile : IEquatable<Profile>
{
public string Name { get; set; }
public string Email { get; set; }
public bool Equals(Profile other)
{
return this.Email == other.Email;
}
}
public class Auth0Profile : Profile
{
public new string Email { get; set; }
public new string Name { get; set; }
public string Connection { get; set; }
public string Password { get; set; }
public bool VerifyEmail { get; set; }
}
public class SharePointProfile : Profile
{
public int Id { get; set; }
public string LoginName { get; set; }
public string Title { get; set; }
public new string Email { get; set; }
public bool IsSiteAdmin { get; set; }
}