Entity Framework排序

  public ActionResult Index()
{
using (ApplicationDbContext db = new ApplicationDbContext())
{
//var log = db.Log.ToList();
//return View(log); /* order by date asc
var log = from p in db.Log orderby p.Date select p;
return View(log.ToList());
* */ /* order by date desc
var log = from p in db.Log orderby p.Date descending select p;
return View(log.ToList());
* */ /* order by date asc
var log = db.Log.OrderBy(p => p.Date).ToList();
return View(log);
* */ /* order by date desc
var log = db.Log.OrderByDescending(p => p.Date).ToList();
return View(log);
* */ /* order by date desc,id asc
var log = from p in db.Log orderby p.Date descending, p.ID select p;
return View(log.ToList());
* */ //order by date desc,id asc
var log = db.Log.OrderByDescending(p => p.Date).ThenBy(p => p.ID).ToList();
return View(log);
}
}

  

上一篇:ffmpeg中AVBuffer的实现分析


下一篇:2017 United Kingdom and Ireland Programming Contest (UKIEPC 2017)