score:2

Accepted answer

You can accomplish this using LINQ's Any method:

var query = toIEnumerable.GroupBy(c => c.country).Select(r =>
{
    bool someWithNoGrades = r.Any(i => i.grade == null);

    return new
    {
        r.Key,
        sumGrade = !someWithNoGrades ? r.Sum(f => f.grade) : null
    };
});

Related Articles