2012-07-24 73 views
0

如何添加OrderBy(a=>a.SortField)或「的SortField」如何排序依據添加到查詢結果果園

var slideShowProducts = _contentManager.Query<JewelleryProductPart, JewelleryProductPartRecord>("JewelleryProduct") 
       .Join<CustomPropertiesPartRecord>() 
       .Where(cpp => cpp.CustomOne == catViewModel.Number) 
       .Join<BodyPartRecord>() 
        .List()            
        .Select(sp => new SlideShowProductViewModel 
        { 

         Count = sp.Count, 
         CategoryName = sp.Fields.Single(f => f.PartFieldDefinition.Name == "Category").Storage.Get<string>(""), 
         SortField = sp.Fields.Single(f => f.PartFieldDefinition.Name == "Sort Field").Storage.Get<string>(""), 
         Description = sp.Get<BodyPart>().Text 
        }).ToList(); 


       SlideShowProductsViewModel products = new SlideShowProductsViewModel(); 
       products.Number = catViewModel.Number; 
       products.CategoryName = catViewModel.Name; 
       products.SlideShowProducts = slideShowProducts;     


       productList.Add(products); 

回答

0

你試試下面的下面的查詢結果排序?

products.SlideShowProducts =slideShowProducts.OrderBy(a=>a.SortField).ToList(); 
+0

如果這是一個可能無法工作的字段。投影可以在字段上進行排序。更好的猜測可能會去看Orchard.Projections中的代碼。 – 2012-07-25 11:08:18