Users class:
public class User
{
public int ID { get; set; }
public string Email { get; set; }
}
Code:
var usersL = new List<User>()
{
new User{ID = 1,Email = "abc@foo.com"},
new User{ID = 2,Email = "def@foo.com"}
};
var usersR = new List<User>()
{
new User{ID = 1,Email = "abc@foo.com"},
new User{ID = 2,Email = "def@foo.com"}
};
var both = (from l in usersL select l)
.Intersect(from users in usersR select users);
foreach (var r in both)
Console.WriteLine(r.Email);
Which returns 0 results.
I know I can accomplish something similar by using join, but I want to use Intersect because A) this is eventually going to work on some DB code and we want to use this function (too long to go into why) and B) I'm just plain curious as to why Intersect isn't working here.
var both = from l in usersL
join r in usersR on l.ID equals r.ID
select l;