【发布时间】:2011-04-22 13:18:47
【问题描述】:
假设您有一个 Product 类,其成员声明为嵌套类型 ProductFeature:
public class Product {
public ProductFeature ProductID {get;set;}
public ProductFeature ProductName {get;set;}
}
public class ProductFeature {
public int FeatureID {get;set;}
public string FeatureName {get;set;}
}
在某个地方,您有一种方法可以将所有产品加载为PagedList<Product>:
var list = db.GetProductList();//returns PagedList<Product>:
现在您要过滤并应用一些OrderBy 和ThenBy:
var sorted = model.Products.OrderBy(x => x.ProductName).ThenBy(x=>x.ProductID);
sorted 的结果可以被视为IEnumerable<T> 和IOrderedEnumerable<T>。
问题是当我们尝试将sorted 转换回PagedList<Product> 或List<Product> 时。
base {System.SystemException}: {"At least one object must implement IComparable."}
Message: "At least one object must implement IComparable."
有什么方法可以再次将sorted 转换为List?
【问题讨论】:
标签: linq c#-4.0 sql-order-by pagedlist