probably a simple Q but still a beginner at this and not sure on how to.... Each WorkStation can have a number of Invoices So my below code will....
store all the workStations, go Through each workStation,
get the last (most recent) invoice for that workStation,
If the invoices date (for the most recent Invoice) is < 12 Months
Add it to the list of sites...
EDIT: Thanks for all the help guys but I am trying to do it through c# and avoid the LINQ searche you guys have mentioned...thanks for everyone who replied...
My new problem being i need to sort the ChosenInvoices list into asceding order and return the first...as i think it is selecting anyone in the list:
var allWorkSites =
(from worksites in db.Work_Sites
select worksites).Distinct().ToList();
List<Object> chosenInvoices = new List<Object>();
foreach (Work_Site worksite in allWorksites)
{
Invoice lastInvoice = worksite.Invoices.LastOrDefault();
if (lastInvoice != null)
{
if (lastInvoice.Invoice_Date < DateTime.Now.AddMonths(-12))
{
chosenInvoices.Add(workstation);
}
}
}