Вы можете получить желаемый результат с помощью плавной реализации Linq.Except () :
List<Employee> employees = new List<Employee>
{
new Employee { EmployeeID = 1, FirstName = "John", LastName = "Smith" },
new Employee { EmployeeID = 2, FirstName = "Jane", LastName = "Doe" },
new Employee { EmployeeID = 3, FirstName = "Eddie", LastName = "Punchclock" }
};
List<Employee> managers = new List<Employee>
{
new Employee { EmployeeID = 2, FirstName = "Jane", LastName = "Doe" },
};
var nonManagerEmployees = employees.Except(managers, x => x.EmployeeID)
.Select(x => new
{
x.EmployeeID,
EmployeeName = x.FirstName + " " + x.LastName
});
foreach(var entry in nonManagerEmployees)
{
Console.WriteLine(entry.EmployeeID+" "+entry.EmployeeName);
}
выход:
1 John Smith
3 Eddie Punchclock