我想知道如何通过两种不同的类型订购,如下一个查询:
var qry = (from m in dc.Orders
select new { m.OrderDate, m.OrderID }).OrderBy(o=>o.OrderDate+o.OrderID).ToList();
bindingSource1.DataSource = qry;
OrdrerDate是日期类型,OrderID是int类型。
答案 0 :(得分:6)
您正在寻找.ThenBy()
:
.OrderBy(o => o.OrderDate).ThenBy(o => o.OrderID).
答案 1 :(得分:1)
我会说:
var qry = (from m in dc.Orders
select new { m.OrderDate, m.OrderID }).OrderBy(o=>o.OrderDate).ThenBy(o.OrderID).ToList();
答案 2 :(得分:1)
试试这个
var qry = (from m in dc.Orders
select new { m.OrderDate, m.OrderID }).OrderBy(o=>o.OrderDate).ThenBy(o.OrderID).ToList();
答案 3 :(得分:1)
您可以使用ThenBy或者您可以编写此Linq查询:
var qry = (from m in dc.Orders
orderby m.OrderDate, m.OrderID
select new {m.OrderDate, m.OrderID}).ToList
bindingSource1.DataSource = qry;