Merging every two objects into single single object making group by a property C# LINQ
If you want to reduce the iteration to get the value for ColumnC and ColumnD and make the code cleaner, you can try using Aggregate instead.
var output = input
             .GroupBy(d =&gt; new {d.ColumnA, d.ColumnB})
             .Select(
                 g =&gt; g.Aggregate(
                     new MappingClass {ColumnA = g.Key.ColumnA, ColumnB = g.Key.ColumnB},
                     (result, next) =&gt;
                     {
                         result.ColumnC ??= next.ColumnC;
                         result.ColumnD ??= next.ColumnD;
                         return result;
                     }))
              .ToList();