开发者

OrderBy in LINQ to Entity

I have this LINQ query and want to add a second orderby.

var clients = from c in context.clients
                                  orderby c.clientname
                                  select new { c, orders = c.orders};

So after this i have an alfabetical list of clients with unorderd ORDERS. I als开发者_如何学JAVAo want to OrderBy on ORDERS.ORDERNUMBER

If possible I want to do all of this in one query.

How to? Please


I suspect you want:

var clients = from c in context.clients
              orderby c.clientname
              select new { c, orders = c.orders.OrderBy(o => o.OrderNumber) };


Tuple<int, string>[] x = new Tuple<int,string>[] {
    new Tuple<int, string>(0, "a"),   
    new Tuple<int, string>(1, "b"),
    new Tuple<int, string>(2, "b"),
    new Tuple<int, string>(2, "a"),
    new Tuple<int, string>(3, "e")
};

var ordered = (from p in x orderby p.Item1 select p).ThenBy(a => a.Item2);

foreach (var item in ordered)
{
    Console.WriteLine(item.Item1.ToString() + " - " + item.Item2);
}

Console.ReadLine();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜