using System.Collections.Generic;
public static void Main()
List<MyEntity> source = new List<MyEntity>
new MyEntity(33, "120A"),
new MyEntity(33, "240B"),
new MyEntity(33, "14CD"),
new MyEntity(33, "984A"),
new MyEntity(34, "120A"),
new MyEntity(34, "240B"),
new MyEntity(35, "14CD"),
new MyEntity(35, "984A"),
new MyEntity(39, "120A"),
new MyEntity(39, "240B"),
new MyEntity(39, "14CD"),
int targetCustomerId = 33;
var targetProducts = source
.Where(x => x.CustomerId == targetCustomerId)
.Select(x => x.ProductId)
var matchedCustomers = source
.Where(x => x.CustomerId != targetCustomerId)
.GroupBy(x => x.CustomerId)
g.Select(p => p.ProductId).Distinct().OrderBy(p => p).SequenceEqual(targetProducts))
Console.WriteLine("Matched customers: " + string.Join(", ", matchedCustomers));
public MyEntity(int customerId, string productId)
public int CustomerId { get; set; }
public string ProductId { get; set; }