我有4列,facilities0id,名稱,日期,數量。我在這裏幾乎沒有問題使用orderby使用linq查詢
如何使用orderby根據數量。我想找到前三排。任何人都可以幫助,謝謝
DataClassesDataContext db = new DataClassesDataContext();
var query = from p in db.Facilities
join v in db.Reservations on p.facilities_id equals v.facilities_id
join c in db.Reservation_Details on v.reservation_id equals
c.resevation_id
where SqlMethods.Like(c.date, "%" + DropDownList1.Text + "%")
select new
{
p.facilities_id,
p.name,
c.date,
Quantity = p.Reservations.Count()
};
GridView1.DataSource = query.GroupBy(x => x.facilities_id)
.Select(g => g.First())
.ToList();
GridView1.DataBind();
int totalRowsCount = GridView1.Rows.Count;
Label2.Text = DateTime.Now.ToShortDateString();
Label3.Text = totalRowsCount.ToString() + " record(s)";
Label4.Text = DropDownList1.Text;
數據在我的數據庫
facilities_id name date Quantity
F001 cc 12-12-2014 3
F002 vv 12-12-2014 2
F003 gg 12-12-2014 1
F004 bb 12-12-2014 5
這是我的期望輸出
facilities_id name date Quantity
F004 bb 12-12-2014 5
F001 cc 12-12-2014 3
F002 vv 12-12-2014 2