2011-05-04 4 views
0

이 LINQ 쿼리가 있는데 두 번째 orderby를 추가하려고합니다.LINQ to Entity의 OrderBy

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

이렇게 나는 비 순차적 주문이있는 클라이언트의 알파벳 목록을 가지고 있습니다. 나는 또한 ORDERS.ORDERNUMBER에 주문하십시오.

가능하면이 모든 것을 하나의 쿼리에서 수행하고 싶습니다.

? 하십시오

+0

당신이 무엇을 의미하는지 분명하지 않다 - 무엇을하면 결과가있을 것으로 예상된다? 고객 목록 또는 주문 목록? –

+0

예 주문 목록의 주문 목록이있는 클라이언트 목록 1 개 –

+0

알겠습니다. 당신은 다른 시퀀스를 주문하려고합니다. 이것은 혼란스러운 일이었습니다. –

답변

1

나는 당신이 원하는 의심 :

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

존 당신은 오늘 내 영웅입니다. –

0
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();