I have the following query to start with:
var query = from p in db.Products
from pc in p.NpProductCategories
where pc.CategoryId == categoryId
select p;
I m 对其应用一些更多的过滤器,最后,我想对结果进行分类:
if (orderBy == ProductSortingEnum.Name)
query = query.OrderBy(x => x.Name);
else
query = query.OrderBy(............);
My big problem (coming from not knowing linq too good) is the ELSE here. How can I sort results by a column that is not in the current result set? I would like to somehow link to another linq query in the orderby. The sorting I m trying to achive is to link to NpProductVariants query using the ProductId to match between NpProductVariant and Products and sort by the Price of the NpProductVariant