• 这个匿名对象没有实现IComparable接口


    https://www.cnblogs.com/felixnet/p/5193086.html

    https://docs.microsoft.com/zh-cn/dotnet/api/system.icomparable-1?redirectedfrom=MSDN&view=netframework-4.7.2

    中文:必须至少有一个对象实现 IComparable。

    序列排序时报这个错误

    lstReports.OrderBy(r => new { r.DepartmentName, r.ReportNo }).ToList(); //error occured

    在LINQ to SQL/Entity中可以这么用,LINQ 2 Object 不能这么用,因为 new { r.DepartmentName, r.ReportNo } 这个匿名对象没有实现IComparable接口,也无法实现这个接口

    其实多字段排序用 ThenBy/ThenByDescending 就可以:

    lstReports.OrderBy(r => r.DepartmentName).ThenBy(r => r.ReportNo).ToList();

  • 相关阅读:
    最长有效括号
    C++ 环形缓存区的实现
    vector的原理与底层实现
    聚合分析与分组
    求两个数的最大公约数
    单例模式
    工厂方法模式
    责任链模式
    适配器模式
    策略模式
  • 原文地址:https://www.cnblogs.com/kelelipeng/p/10084299.html
Copyright © 2020-2023  润新知