At least one object must implement IComparable
中文:必须至少有一个对象实现 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();
At least one object must implement IComparable的更多相关文章
- C#基础之数组排序,对象大小比较
从个小例子开始: 1 2 3 int[] intArray = new int[]{2,3,6,1,4,5}; Array.Sort(intArray); Array.ForEach<int&g ...
- C#数组排序以及比较对象的大小
先来看个小例子吧 ,,,,,}; Array.Sort(intArray); Array.ForEach<int>(intArray,(i)=>Console.WriteLine(i ...
- 【C#】基础之数组排序,对象大小比较(对比器)
C#基础之数组排序,对象大小比较 原文链接:[OutOfMemory.CN] 从个小例子开始: 1 2 3 int[] intArray = new int[]{2,3,6,1,4,5}; Array ...
- C#中如何使用IComparable<T>与IComparer<T>接口(转载)
本分步指南描述如何使用两个接口: IComparer和IComparable.在同一篇文章中讨论这些接口有两个原因.经常在一起,使用这些接口和接口类似 (并且有相似的名称),尽管它们用于不同用途. 如 ...
- ios Object Encoding and Decoding with NSSecureCoding Protocol
Object Encoding and Decoding with NSSecureCoding Protocol February 27, 2014 MISC NSCoding is a fanta ...
- Comparer<T> IComparer<T> IComparable<T>
Comparer<T>.Default Property Comparer<T>.Default doesn't use your FooComparer class. It ...
- 在Asp.Net MVC中实现CompareValues标签对Model中的属性进行验证
在Asp.Net MVC中可以用继承ValidationAttribute的方式,自定制实现Model两个中两个属性值的比较验证 具体应用场景为:要对两个属性值的大小进行验证 代码如下所示: /// ...
- VB.NET vs. C#
VB.NET Program Structure C# Imports System Namespace Hello Class HelloWorld Overloads Shar ...
- (C#) 基本概念一览表
A abstract class An abstract class is a class that must be inherited and have the methods overridden ...
随机推荐
- JPA(4)表表关联关系
在我们做数据库设计的时候,最烦的就是各种表之间的关联关系了,关联关系有:一对多,多对一,一对一,其中还有单向和双向的区别. 1.双向一对多及多对一映射:既然是双向,那么就是同一类的了:双向一对多关系中 ...
- Python: Convert rst to html
pip install sphinx rst2html.py in_file.rst out_file.html
- MaterialRefreshLayout
以上就介绍了比SwipeRefreshLayout更漂亮和强大的下拉刷新控件:Android-MaterialRefreshLayout 1.xml <?xml version="1. ...
- mysql root用户kill connection报ERROR 1095 (HY000): You are not owner of thread N
今日某系统mysql root用户kill connection时报ERROR 1095 (HY000): You are not owner of thread N 按说通过root用户具有supe ...
- Chrome使用技巧(几个月的心得)
转用Chrome,不仅仅因为它的插件之丰富,更因为它的响应速度其他浏览器都望尘莫及.接着我就要写写一些心得. 如何最简易地用上谷歌搜索? 1,下载hosts文件:https://pan.baidu.c ...
- Entity Framework 实体关系总结
刚开始使用 Entity Framework 的时候,由于没有静下心来认真理清关系,走了一些"痛不欲生"的弯路.而我们目前开发的项目都在使用 Entity Framework,为了 ...
- has_many :through VS has_and_belongs_to_many
user role has_and_belongs_to_many role.destroy: 关联表user_roles先删除记录,再role删除. has_many :through user. ...
- English Training Material - 03
Cross-cultural understanding (2) 1 The following text is about cultural diversity. Read it through o ...
- GCC编译器使用
一.GCC简介 通常所说的GCC是GUN Compiler Collection的简称,除了编译程序之外,它还含其他相关工具,所以它能把易于人类使用的高级语言编写的源代码构建成计算机能够直接执行的二进 ...
- C安全问题与指针误用
欢迎关注我的个人博客:www.wuyudong.com, 更多精彩文章与您分享 指针的声明与初始化 1.不恰当的指针声明 考虑如下的声明: int* ptr1, ptr2; // ptr1为指针,pt ...