I'm trying to filter a list on the basis of a criteria and then trying to combine that criteria into a single record. I'm able to this by using this approach:
Dim PortfolioSAA_Bonds = PortfolioSAA.Where(Function(x) x.Description = "Australian Fixed Interest" OrElse x.Description = "International Fixed Interest").ToList()
Dim tmpSAAPortfolio As New SaaPortfolioReportModel
tmpSAAPortfolio.Description = "Bonds"
tmpSAAPortfolio.RiskProfileAllocation = PortfolioSAA_Bonds.Sum(Function(x) x.RiskProfileAllocation)
tmpSAAPortfolio.SAAVariation = PortfolioSAA_Bonds.Sum(Function(x) x.SAAVariation)
tmpSAAPortfolio.ActualSAA = PortfolioSAA_Bonds.Sum(Function(x) x.ActualSAA)
and then
PortfolioSAACustom = PortfolioSAA.Except(PortfolioSAA_Bonds).ToList()
PortfolioSAACustom.Add(tmpSAAPortfolio)
Is this possible to use a single LINQ statement to filter the above values on into a single record with a unique description (like I'm using 'Bonds') above.
I tried using the following but it didn't work:
Dim ttt = From j In PortfolioSAA
Where j.Description = "Australian Fixed Interest" OrElse j.Description = "International Fixed Interest"
Group By x = New With {Key .Description = "Bonds", Key .RiskProfileAllocation = j.RiskProfileAllocation, Key .SAAVariation = j.SAAVariation, Key .ActualSAA = j.ActualSAA} Into g = Group
Select New SaaPortfolioReportModel With {
.Description = "Bonds",
.RiskProfileAllocation = g.Sum(Function(r) r.RiskProfileAllocation),
.SAAVariation = g.Sum(Function(r) r.SAAVariation),
.ActualSAA = g.Sum(Function(r) r.SAAVariation)
}