我有那个课
public class jQGridModel
{
public List<jQGridModelItem> Items { get; set; }
public class jQGridModelItem
{
public DBUser UserItem { get; set; }
public int ItemsSold { get; set; }
}
}
和DBUser
类(由实体框架生成)
public class DBUser
{
public string UserName { get; set; }
public string UserID { get; set; }
public string PromoCode { get; set; }
...
}
我有jQGridModel
一些反对Items
。这是“简单”的问题 - 我想Items
根据UserName
我试过了
jQGridModel result = new jQGridModel();
result.Items = GetItems();
result.Items = result.Items.OrderByDescending(x => x.UserItem.UserName).ToList();
但我看到收集顺序没有改变。我究竟做错了什么 ?
完整代码:
var query = (from x in db.User
where (...)
select x);
var totalRecords = query.Count();
jQGridModel result = new jQGridModel();
result.Items = query.OrderBy(x => x.UserID).Skip(page * pageSize)
.Take(pageSize)
.Select(x => new jQGridModel.jQGridModelItem
{
UserItem = x,
ItemsSold = (from o in db.Order
where
o.PromoCode.Equals(x.PromoCode)
select o).Count()
})
.ToList();
result.Items = result.Items.OrderByDescending(x => x.UserItem.UserName).ToList();