I have 3 tables Pamphlets, Categories and Program. The Pamphlet table has a CategoryID and ProgramID column. The following code works:
var pamphlets = db.Pamphlets.Include("Category").Include("Program").ToList();
What I need to do is sort by CategoryName (Category table) and then PamphletName (Pamphlet table).
You would simply chain a call to ThenBy():
var sortedPamphlets = db.Pamphlets.Include("Category").Include("Program")
.OrderBy(p => p.Category.CategoryName)
.ThenBy(p => p.PamphletName)
.ToList();
How about:
var pamphlets = (from p in db.Pamphlets.Include("Category").Include("Program")
orderby p.Category.CategoryName, p.PamphletName
select p).ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With