I am trying to merge 2 classes into a third on the date properties, for binding to a graph I have already setup.
public class Last30DaysHours
{
public DateTime Date { get; set; }
public float Hours { get; set; }
public float LostHours { get; set; }
}
public class MachineHours
{
public DateTime Date { get; set; }
public float Hours { get; set; }
}
into
public class GraphLast30Days
{
public DateTime Date { get; set; }
public float Hours { get; set; }
public float LostHours { get; set; }
public float SelectedMachine { get; set; }
}
So far I have this linq statement which almost compiles.
The error with the current statment is “‘x’ does not exist in the current context”.
I know what this means but I don’t know how to make it accessable in the statement.
IEnumerable<GraphLast30Days> last30DaysMachineHoursSelect = _last30DaysMachineHours
.Select(p => (_last30Days
.Where(x => x.Date == p.Date) <=
(new GraphLast30Days {
Date = x.Date,
Hours = x.Hours,
LostHours = x.LostHours,
SelectedMachine = p.Hours
})));
My question is how do I make x accessable by the second half of the statement or what is a better statement to achieve the same results?
Thanks for the help.
You’d wont to use join to join your collections by date (not sure I got the correct proeprties, but you got the idea):
Or with alternative syntax:
In case you don’t wont to filter out missing values you’ll need to do left join: