I have a Model called JobReport which looks like this (simplified)
public class JobReport
{
public JobReport()
{
WorkOrders = new List<WorkOrder>();
}
public int JobID { get; set; }
public List<WorkOrder> WorkOrders{ get; set; }
}
public class WorkOrder
{
public WorkOrder()
{
Total = 0;
}
public string Trade { get; set; }
public int WorkOrderID { get; set; }
public decimal? Total { get; set; }
}
I'd like to run a Linq query which gets me all the Jobs that have WorkOrders that have a trade which is in a passed array.
var trades = new string[] { }
I've tried something like the following which doesn't work, as it tries to get me a list of workorders, when I actually need the underlying jobs.
The problem appears to be because I'm calling Select
var jobsDB = db.Jobs.Include(x=>x.WorkOrders).ToList();
var jobs = (from p in jobsDB
select new JobReport()
{
JobID = p.JobID,
WorkOrders = p.WorkOrders.ToList()
}
jobs = jobs
.Select(x => x.WorkOrders
.Where(y => trades.Contains(y.Trade)));
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…