如何排序对象列表

时间:2015-10-30 13:07:34

标签: linq

无论我做什么,我似乎无法按发票名称对列表进行排序。 我有一个客户端类,其中包含Igolection of Invoices

我的Repoistory

public Client FindClientById(string id)
        {

            Client client = RepositorySet.Include("Account").Include("Invoice").FirstOrDefault(c => c.Id == id && !c.IsDeleted);

            return client;
        }

在我的控制器上

Client clientToEdit = _clientService.FindClientAndInvoicesById(id);
List<Invoice> SortedList = clientToEdit.invoices.OrderBy(o => o.Name).ToList();

我做错了什么?

1 个答案:

答案 0 :(得分:1)

试试这个

SortedList.OrderBy(x => x.field)

List<Invoice> SortedList = clientToEdit.invoices.ToList().OrderBy(o => o.Name);