I was wondering if there's a better way of doing LINQ projections than what I'm doing below. This method is one of many methods creating a view of an object tree.
The first thing that I don't like is that I'm returning an anonymous object. Should I create a BreakdownReport
class or something else instead?
Also, the copying of property values from right to left is a bit of a hassle.
public object GetBreakdownsReport()
{
return CurrentSecurity
.Breakdowns
.SelectMany(b => b.BreakdownLines, (b, bdl) => new
{
AccountId = b.Account.Id,
Structure = b.Account.Structure,
Market = b.Account.Market,
BeneficiaryId = bdl.Beneficiary.Id,
BeneficiaryType = bdl.Beneficiary.BeneficiaryType,
CountryCode = bdl.Beneficiary.CountryCode,
CountryName = bdl.Beneficiary.CountryName,
DtaRate = bdl.Beneficiary.DtaRate,
HoldingCode = b.HoldingCode,
InstructionAmount = bdl.InstructionAmount,
NarrativeText = bdl.Narrative.Text,
Chapter = bdl.Narrative.Chapter,
Paragraph = bdl.Narrative.Paragraph,
Subparagraph = bdl.Narrative.Subparagraph,
TaxRate = bdl.Narrative.TaxRate,
})
.ToList();
}