Accepted answer

Try the following

var list = originalList
    .GroupBy(x => x.Number)
    .Select(x => x.OrderBy(y => y.Percentage).First())

This query will first group the items by the Number value. It will then order each group by the percentage and select out the first element (which is the lowest).


  var query = (from l in lst
         group l by l.Number into g
         select g.Min(x => x.Percentage)).ToList();


Changing this up based on the interpretation that by "LINQ" the poster desires query-comprehension syntax instead of dot-syntax (otherwise the other responses suffice):

var query =
    from i in list
    group i by i.Number into gj
    select gj.OrderBy(x => x.Percentage).First();

But this still uses a lot of dot-syntax for the ordering. Which would be the functional equivalent of:

var query =
    from i in list
    group i by i.Number into gj
        (from i in gj
        orderby i.Percentage
        select i).First();

If you don't like the .First() call on the end, that's going to be a challenge that either will not have a solution within the LINQ language transforms or the solution you end up with will not be the clean solution that IMHO dot syntax provides for this problem. Query comprehensions can often make things simpler, but in this case I prefer the dot-syntax:

var query =
    list.GroupBy(i => i.Number)
        .Select(gj => gj.OrderBy(i => i.Percentage).First());

The gj.OrderBy(...).First() portion accomplishes a More-LINQ-style MinBy operation (See Jon Skeet's post)


Would this work?

collection.GroupBy(item => item.Number).Select(group => group.Min())


var query = from x in list
            group x by x.Number into x
            select x.OrderBy(y => y.Percentage).First();

Related Query

More Query from same tag