I need to perform a LINQ query for both a time period from a database table (Period) and a list of invoices from a table (Invoice) that fall within the period’s start and end dates. There is no key reference between the two tables, how can I do the Invoice subquery?
I am trying to do something similar to the following:
var query = (from p in db.DataContext.Periods // Subquery i in db.DataContext.Invoices let InvoiceAmount = i.Where(t => t.InvoiceDate >= p.StartDate && t.InvoiceDate <= p.EndDate) select new PeriodView ( p.Name, p.StartDate, p.EndDate, InvoiceAmount.Count() ));
I’m assuming that the PeriodView constructor looks something like this