Reputation: 80
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.
Upvotes: 2
Views: 834
Reputation: 727067
As you can see I've tried the
Concat
andUnion
method which I am having no success with either.
This is because you've ignored their return value. You should have done either
results = results.Concat(resultsSetup);
if you want to append all items of resultsSetup
to results
, or
results = results.Union(resultsSetup);
if you would like to obtain a union (i.e. remove all duplicates).
Upvotes: 3