LINQ 中使用 Distinct 的 Compare过滤重复的字段
public class ProcurementPhotoMenuCompare : IEqualityComparer<ProcurementPhotoMenuModel> { public bool Equals(ProcurementPhotoMenuModel x, ProcurementPhotoMenuModel y) { return (x.CategoryType == y.CategoryType); } public int GetHashCode(ProcurementPhotoMenuModel obj) { return obj.ToString().ToLower().GetHashCode(); } }
使用;
return m.Select(t => new ProcurementPhotoMenuModel { CategoryType = t.Identifier ?? "", MenuTitle = t.Title ?? "", PhotoMenuType = t.Attribute01 ?? "" }).Distinct(new ProcurementPhotoMenuCompare()).ToList();
🐳 作者:dupeng0811 📢 版权:本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接 💬 留言:同时 , 如果文中有什么错误,欢迎指出。以免更多的人被误导。 |
|