1
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; }
...
}
我有一些Items
jQGridModel
對象。而這裏的「簡單」的問題 - 我想將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();
不是指定的'result.Items'兩次,如果你這樣做'VAR項目,會發生什麼=結果.Items.OrderByDescending(x => x.UserItem.UserName).ToList();'?收藏是否重新訂購? – mattytommo
很難說這些片段有什麼問題。請發佈簡短但完整的*程序來證明問題。 –
@mattytommo不會解決問題,如果有一個 –