I have a piece of code here:
var grouped = nonGrouped.GroupBy(x => new
{
x.Id,
x.Col1,
x.Col2
}).Select(x => new MyDbTable
{
Id = x.Key.Id,
VALUE = x.Sum(y => y.Value),
Col1 = x.Key.Col1,
Col2 = x.Key.Col2
}).ToList();
//Filter out rows with the same Col1/Col2 combination
var dbTableList = new List<MyDbTable>();
grouped.ForEach(x =>
{
if (!dbTableList.Any(a => a.Col1 == x.Col2 && a.Col2 == x.Col1))
{
dbTableList.Add(x);
}
});
I would like to remove the code under the comment "//Filter out rows with the same Col1/Col2 combination" and somehow add this functionality to my LINQ statement above the comment