排序列表时OrderBy不起作用,Resharper也显示警告“未使用纯方法的返回值”

时间:2018-03-23 04:29:47

标签: c# asp.net entity-framework linq resharper

我已经咨询了Warning in Resharper "Return value of pure method is not used"帖子但未找到解决方案

看看我的代码

var listDetail = (from p in Expense.GetAll()
    where p.Group == "001"
    select new ExpenseViewModel()
    {
        ExpenseC = p.ExpenseC,
        Group = p.Group,
        Cost = p.Cost,
    }).ToList();
listDetail.OrderBy(p => p.ContainerSizeI); //warning displayed at OrderBy with content "return value of pure method not used"

因此,listDetail变量没有按照我想要的升序排序

1 个答案:

答案 0 :(得分:2)

您需要将OrderBy移动到您的方法链中。

var listDetail = (from p in Expense.GetAll()
where p.Group == "001"
select new ExpenseViewModel()
{
    ExpenseC = p.ExpenseC,
    Group = p.Group,
    Cost = p.Cost,
})
.OrderBy(p => p.ContainerSizeI)
.ToList();