linq merge elements with orderby

Posted by Sanja Melnichuk on Stack Overflow See other posts from Stack Overflow or by Sanja Melnichuk
Published on 2011-03-11T13:31:16Z Indexed on 2011/03/11 16:10 UTC
Read the original article Hit count: 318

Filed under:
|

Hi all. I need to select all terminals sorted by Attributes[2]

// get all query
IQueryable<ITerminal> itt = repository.Terminals.GetQuery();

// get all with Attributes[2]
IQueryable<ITerminal>  itt2 = itt
    .Select(item => new
    {
        attrs = item.Attributes[2],
        term = item 
    })
    .OrderBy(x => x.attrs)
    .Select(x => x.term);

Now how to select from itt all terminals but ordered by itt2 results? How to order them by itt2?

Example:

itt = c,d,r,a,w,b

itt2 = a,b,c // after select

and after merge: a,b,c d,r,w

Thanks all

© Stack Overflow or respective owner

Related posts about c#

Related posts about LINQ