In my code below I would like to get Invoices
with their aggregate InvoiceLine
totals and also a list of Tracks
associated with each Invoice
.
var screenset =
from invs in context.Invoices
join lines in context.InvoiceLines on invs.InvoiceId equals lines.InvoiceId
join tracks in context.Tracks on lines.TrackId equals tracks.TrackId
group new { invs, lines, tracks }
by new
{
invs.InvoiceId,
invs.InvoiceDate,
invs.CustomerId,
invs.Customer.LastName,
invs.Customer.FirstName
} into grp
select new
{
InvoiceId = grp.Key.InvoiceId,
InvoiceDate = grp.Key.InvoiceDate,
CustomerId = grp.Key.CustomerId,
CustomerLastName = grp.Key.LastName,
CustomerFirstName = grp.Key.FirstName,
CustomerFullName = grp.Key.LastName + ", " + grp.Key.FirstName,
TotalQty = grp.Sum(l => l.lines.Quantity),
TotalPrice = grp.Sum(l => l.lines.UnitPrice),
Tracks = grp.SelectMany(t => t.tracks)
};
However, in the last line were I did a SelectMany is giving me an error:
Tracks = grp.SelectMany(t => t.tracks)
Error:
The type arguments cannot be inferred from the usage. Try specifying the type arguments explicitly.
Any ideas why?
Thanks in advance.