Group by linq multiple columns csharp

Code Example - Group by linq multiple columns csharp

                
                        var query = (from t in Transactions
             group t by new {t.MaterialID, t.ProductID}
             into grp
                    select new
                    {
                        grp.Key.MaterialID,
                        grp.Key.ProductID,
                        Quantity = grp.Sum(t => t.Quantity)
                    }).ToList();
                    
                
 

linq group by multiple

                        
                                .GroupBy(x => new { x.Column1, x.Column2 })
                            
                        
 

Related code examples