Can I make this two LINQ queries into one query only?

Posted by Holli on Stack Overflow See other posts from Stack Overflow or by Holli
Published on 2010-05-27T08:53:38Z Indexed on 2010/05/27 9:11 UTC
Read the original article Hit count: 246

Filed under:
|

From a List of builtAgents I need all items with OptimPriority == 1 and only 5 items with OptimPriority == 0. I do this with two seperate queries but I wonder if I could make this with only one query.

IEnumerable<Agent> priorityAgents =
from pri in builtAgents where pri.OptimPriority == 1 select pri;

IEnumerable<Agent> otherAgents =
(from oth in builtAgents where oth.OptimPriority == 0 select oth).Take(5);

© Stack Overflow or respective owner

Related posts about LINQ

Related posts about query-optimization