我的排序在Linq中未正确返回[关闭]

问题描述 投票:-4回答:1

我正在尝试确定为什么我的排序不起作用。我没有收到错误,方法只返回未排序的列表。

public IEnumerable<Customer> GetSubsetOfEmployees(int startRows, int maxRows, string sortExpression)
{
    NorthwindEntities ndc = new NorthwindEntities();
    var customerQuery =
        from c in ndc.Customers
            //https://code.msdn.microsoft.com/101-LINQ-Samples-3fb9811b
        select c;

    if (string.IsNullOrEmpty(sortExpression)) sortExpression = "CustomerID";

    Dictionary<string, Func<IEnumerable<Customer>, IEnumerable<Customer>>> orderings = new Dictionary<string, Func<IEnumerable<Customer>, IEnumerable<Customer>>>()
    {
        { "CustomerID",  x1 => x1.OrderBy(x => x.CustomerID) },
        { "CompanyName",  x1 => x1.OrderBy(x => x.CompanyName) },
        { "CustomerID DESC",  x1 => x1.OrderByDescending(x => x.CustomerID) },
    };

    orderings[sortExpression](customerQuery.Skip(startRows).Take(maxRows));

    return customerQuery;
}
c# entity-framework linq
1个回答
2
投票

您不返回已排序的集合。

© www.soinside.com 2019 - 2024. All rights reserved.