我有这个sql语句:
SELECT QuestionNo,ActivityID,GROUP_CONCAT(CONCAT(问题,'[',
答案']')SEPARATOR'')AS来自问题GROUP BY
QuestionNo,ActivityID OrderbyquestionHintID
我需要在linq lambda中使用它,到目前为止,我所拥有的是
IList<QuestionHint> lstRecords = context.questionhints.GroupBy(x => new { x.QuestionNo, x.ActivityID, x.TaskID }).ToList().Select(g => new QuestionHint()
{
QuestionNo = g.Key.QuestionNo,
ActivityID = g.Key.ActivityID,
TaskID = g.Key.TaskID,
joined = String.Join(" ",
g.Select(i => i.QuestionContent + "[" + i.Answer + "]")),
joinOption = String.Join(" ",
g.Select(a => "[" + a.Option1 + "," + a.Option2 + "]"))
}).Where(x => x.TaskID == listTask && x.ActivityID == listActivity)
//.Take(50)
.ToList();
return lstRecords;
如何添加Orderby?因为当我在查询中使用join时,检索的记录是乱序的,因为不能保证顺序是正确的,如何将OrderBy questionHintID(表的主键)添加到上述lambda中?
最佳答案
您是否尝试过.OrderByDescending(questionhints => questionhint.ID)?希望这可以帮助!!
关于c# - LINQ Lambda Orderby的SQL语句,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17461483/