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 ...
随机推荐
- Little Jumper---(三分)
Description Little frog Georgie likes to jump. Recently he have discovered the new playground that s ...
- java File.mkdirs和mkdir区别
File f = new File("e://xxx//yyy"); System.out.println(f.mkdirs());//生成所有目录,一般来说,这个方法稳健性更好, ...
- spring bean加载顺序指定方式之一
在某些情况下,我们在容器启动的时候做一些事情,举个例子,加载缓存等.. 此时我们会希望某个bean先被加载并执行其中的afterpropertiesset方法. 因为spring默认是通过contex ...
- uploadify API
apifunctionjavascriptflashsecurity服务器 属性: uploader : uploadify.swf 文件的相对路径,该swf文件是一个带有文字BROWSE的按钮,点击 ...
- C# Out 传值
public void Out(out int a, out int b) {//out相当于return返回值 //可以返回多个值 //拿过来变量名的时候,里面默认为空值 a=1; b=2; } s ...
- JavaScript正则表达式小记
RegExp.html div.oembedall-githubrepos{border:1px solid #DDD;border-radius:4px;list-style-type:none;m ...
- Thread.CurrentPrincipal & HttpContext.Current.User
据说要这样写才稳妥 // This principal will flow throughout the request.VoyagerPrincipal principal = new Voyage ...
- 【读书笔记】iOS-GCD-Dispatch Source
一,Dispatch Source是BSD系内核惯有功能kqueue的包装. 参考资料:<Objective-C高级编程 iOS与OS X多线程和内存管理>
- vector,arraylist, linkedlist的区别是什么
LinkedList类 LinkedList实现了List接口,允许null元素. 此外LinkedList提供额外的get,remove,insert方法在LinkedList的首部或尾部. Lin ...
- IOS开发关于测试的好的网址资源
1. 高级自动化单元测试,推荐看LeanCloud 工程师的李智维的自动化单元测试的直播录影李智维的演示github 2.iOS开发-单元测试 这只是一篇简单的ios测试介绍 3.iOS单元测试 来自 ...