也许我错过了使用?(我使用System.Li).有Distinct没有问题.
这是我想要添加DistinctBy的命令
List<Capture> list = db.MyObject.Where(x => x.prop == "Name").ToList();
Run Code Online (Sandbox Code Playgroud)
Sat*_*pal 16
您可以添加扩展方法
public static IEnumerable<T> DistinctBy<T, TKey>(this IEnumerable<T> items, Func<T, TKey> property)
{
return items.GroupBy(property).Select(x => x.First());
}
Run Code Online (Sandbox Code Playgroud)
你可以像使用它一样
List<Capture> list = db.MyObject.Where(x => x.prop == "Name")
.DistinctBy(y=> y.prop )
.ToList();
Run Code Online (Sandbox Code Playgroud)
或者,您可以使用DistincyBy通过MoreLinq提供的.