0

我有表“客户”,它有 3 列:SQL Server 中的“Col1”、“Col2”、“Col3”。

我想获取 Col2 值多次出现的所有行。

这是我的查询:

Context.Customers.Where(x => x.Col2.Count() > 1).ToList();

但它不起作用。你知道任何想法吗?

谢谢

4

1 回答 1

0

使用分组

Context.Customers.GroupBy(x => x.Col2) // group by Col2 value
                 .Where(g => g.Count() > 1) // get groups with more than one item
                 .SelectMany(g => g) // flatten results
                 .ToList();
于 2013-06-28T13:39:34.393 回答