I have the following code which is getting me one set of results and then another (resultsSetup) which is exactly the same based on if a condition is met.
// use Linq to query the downtime data
var results = from t in this.MachineEvent.Transactions.OfType<Logic.DowntimeScrapTransaction>()
where t.TransactionType == Logic.Enums.MachineEventTransactionType.DowntimeScrapTransaction
group t by t.Reason.Group into grps
let totalDowntime = grps.Sum(g => g.DowntimeDuration.TotalMinutes)
orderby totalDowntime descending
select new { Key = grps.Key, values = grps, TotalDownTime = grps.Sum(g => g.DowntimeDuration.TotalMinutes) };
if (this.MachineEvent.MachineState == Logic.Enums.MachineState.Production)
{
var resultsSetup = from t in this.MachineEvent.GetSetupMachineEvent().Transactions.OfType<Logic.DowntimeScrapTransaction>()
where t.TransactionType == Logic.Enums.MachineEventTransactionType.DowntimeScrapTransaction
group t by t.Reason.Group into grps
let totalDowntime = grps.Sum(g => g.DowntimeDuration.TotalMinutes)
orderby totalDowntime descending
select new { Key = grps.Key, values = grps, TotalDownTime = grps.Sum(g => g.DowntimeDuration.TotalMinutes) };
results.Concat(resultsSetup);
results.Union(resultsSetup);
}
What I am trying to do is simply combine these two results together. As you can see I've tried the Concat and Union method which I am having no success with either.
Unionwork on anonymous types?ConcatorUnionin a variable. They both return a new query, they don't change either input query. (@germi Yeah, it's magic :) )Unionhappily takes advantage of it. From the spec, TheEqualsandGetHashcodemethods on anonymous types override the methods inherited fromobject, and are defined in terms of theEqualsandGetHashcodeof the properties, so that two instances of the same anonymous type are equal if and only if all their properties are equal.