LINQ group by sum
var attributeTotalValues = (from a in objValue group a by new { a.ProductTypeID, a.AttributeCode } into b select new { ProductTypeID = b.Key.ProductTypeID, AttributeCode = b.Key.AttributeCode, TotalAttributeValue = b.Sum(a => a.AttributeValue.ToDecimal()) }); var objValue = (from a in LinqMetaData.PMExtendAttribute join b in LinqMetaData.PMProjectProductUnit on new { RefRecordID = a.RefRecordID, RefTable = a.RefTable, RecordStatus = a.RecordStatus } equals new { RefRecordID = b.ProjectProductUnitID, RefTable = "PM_ProjectProductUnit", RecordStatus = "Active" } where b.RecordStatus != "Inactive" && b.ProjectID == intProjectID && ids.Contains(b.ProjectProductUnitID) select new { ProductTypeID = b.ProductTypeID, ProjectProductUnitID = b.ProjectProductUnitID, AttributeCode = a.AttributeCode, AttributeValue = a.AttributeValue });