【问题标题】:C# LinqToExcel, Distinct showing all results - tried online solutions, couldn't solveC# LinqToExcel, Distinct 显示所有结果 - 尝试在线解决方案,无法解决
【发布时间】:2018-07-08 16:10:13
【问题描述】:
  var ItemMaster = new ExcelQueryFactory("E:\\Group Item Master.xlsx");

        var ItemList = (from x in ItemMaster.Worksheet()
                        select new
                        {
                            CategoryName = x["CategoryName"],
                            GroupName = x["GroupName"],
                            ModelNo = x["ModelNo"],
                            Description = x["Description"],
                            Code = x["Code"]
                        }).ToList();


        var DistinctCategory = ItemList.Select(x => x.CategoryName).ToArray().Distinct();
        //shows categoryname repeated


        var iteml = ItemList.GroupBy(x => x.CategoryName);
        var DistinctCategoryTwo = iteml.Select(x => x.First()).ToList();
        //shows categoryname repeated

【问题讨论】:

  • 你确定它真的是重复的,而不是不同的大小写或额外的空间?

标签: c# linq linq-to-excel


【解决方案1】:

抱歉,这是 linqToExcel 特定问题

 var CategoryList = ItemList.Select(x => x.CategoryName.Value).Distinct().ToList();

需要值列来修复它

【讨论】:

  • 你不需要ToList之前的Distinct
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-16
  • 1970-01-01
  • 2014-09-18
  • 1970-01-01
  • 2012-07-23
  • 1970-01-01
相关资源
最近更新 更多