我正在尝试根据特定规范TypeId的TextValue通过复杂对象的子列表对复杂对象的父列表进行排序。
我有以下课程:
public class Product
{
public long Id {get;set;}
public string Name {get;set;}
public List<Specification> Specifications {get;set;}
}
public class Specification
{
public long Id {get;set;}
public long TypeId {get;set;}
public string TextValue {get;set;}
}
我想根据产品的特定规格对我的产品进行排序。用例示例:对具有TypeId = 3的规范的TextValue上的产品进行排序((一个产品只能具有一个具有TypeId 3的规范))
我的产品列表如下:
IQueryable<Product> productQuery = _context.Products.Include("Specifications");
SortTypeId是我要订购产品列表的规格类型。
这是我试图做的:
productQuery = productQuery
.OrderBy(pq => pq.Specifications
.OrderBy(s => s.TypeID == SortTypeID ? Int32.MinValue : s.Id)
.ThenBy(v => v.TextValue));
这提供以下例外:
System.ArgumentException: 'DbSortClause expressions must have a type that is order comparable.
Parameter name: key'
[我还尝试通过带有Indexof的sortedProductIds列表对IQueryable进行排序,但是这也不起作用(延迟加载的IQueryable不支持IndexOf。)>
我正在尝试根据特定规范TypeId的TextValue通过复杂对象的子列表对复杂对象的父列表进行排序。我有以下课程:公共课程...
由于您说一个产品只能有一个SortTypeID
类型的规范,如果您在查询中按顺序加入单个规范怎么办?