我在做查詢,像這樣:LINQ的OrderByDescending不工作
隨着加入
public IEnumerable<ProblemsViewModel_Base> GetProblemsSearchClassification(string searchTerm)
{
var subjectProblems =
from p in aux_problem
join sub in Subject on p.aux_ClassificationID.Id equals sub.Id
where sub.Title.Contains(searchTerm)
orderby p.CreatedOn descending
select new ProblemsViewModel_Base
{
aux_CustomID = p.aux_CustomID
,
Id = p.aux_problemId.Value
,
title = p.aux_name
,
CreatedOn = p.CreatedOn.Value
};
return subjectProblems;
}
而且沒有加入
public IEnumerable<ProblemsViewModel_Base> GetProblemsSearchDetails(string searchTerm){
var detailsProblems = aux_problem
.Where(p => p.aux_CustomID.Contains(searchTerm))
.OrderByDescending(c => c.CreatedOn)
.Select(i => new ProblemsViewModel_Base
{
aux_CustomID = i.aux_CustomID
,
Id = i.aux_problemId.Value
,
title = i.aux_name
,
CreatedOn = i.CreatedOn.Value
});
return detailsProblems;}
後三位的查詢,我參加並獲得disctinct結果附:
var joinedResults = detailsResults.Union(requestorResults).Union(classificationResults);
var distinctResults = joinedResults.GroupBy(p => p.Id).Select(p => p.First())
我的問題出現在結果中,我使用第二個查詢(沒有連接的那個)的聯合,結果沒有排序,但如果我避免使用聯合查詢,結果是有序的。
這可能是這裏的問題?謝謝!