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();
原文地址:https://www.cnblogs.com/dupeng0811/p/2821920.html