我的查询似乎并不尊重我的order by子句,
有人可以帮我解决这个问题吗?
Dim Result = ((From z As lnkCategorySubCategory In dbContext.lnkCategorySubCategories
Join x As SubItem In dbContext.SubItems On x.Id Equals z.CategoryId
Join p As lnkItemsCategory In dbContext.lnkItemsCategories On z.CategoryId Equals p.ItemCategoryId
Order By z.IsHeadColumn Descending
Order By z.Order Descending
Select x.Name)).Distinct
答案 0 :(得分:1)
如果没有更多信息,我无法告诉您导致问题的原因。但是,如果我采取疯狂的猜测,我建议你改变这个:
Order By z.IsHeadColumn Descending
Order By z.Order Descending
对此:
Order By z.IsHeadColumn, z.Order descending
答案 1 :(得分:0)
我觉得orderby z.IsHeadColumn descending, z.Order descending
应该有效
答案 2 :(得分:0)
这里的问题是我没有选择我选择订购的列,所以我需要写更多这样的东西来解决这个问题
Dim Result = ((From z As lnkCategorySubCategory In dbContext.lnkCategorySubCategories
Join x As SubItem In dbContext.SubItems On x.Id Equals z.CategoryId
Join h As lnkSubItemImageLink In dbContext.lnkSubItemImageLinks On x.Id Equals h.SubItemId
Join p As lnkItemsCategory In dbContext.lnkItemsCategories On z.CategoryId Equals p.ItemCategoryId
Select x.Name, h.ImageLink, z.IsHeadColumn, z.Order)).Distinct.OrderByDescending(
Function(u) u.IsHeadColumn).ThenBy(Function(j) j.Order).ToDictionary(Function(x) x.Name, Function(h) h.ImageLink)