I have the following code:
var sessionsWithError = SessionsFilteredByDate
.Where(i => i.TrackerId > 0 && i.StatusId == 0)
.Select(i => i.SessionId);
var sessionsWithErrorFixed = BusinessClient.Instance.Tracker
.GetAllTrackerAttempts()
.Select(i => i.SessionId);
var sessionsWithErrorIntersection = sessionsWithError.Intersect(sessionsWithErrorFixed);
var sessionsWithErrorsNotFixed = sessionsWithError.Except(sessionsWithErrorIntersection);
Then I have to create a IEnumerable
where I put all the SessionsFilteredByDate
where the sessionID
is included in sessionsWithErrorsNotFixed
, but this operation, since I am using the Any
operator, it's slow, apparently \$O(m*n)\$.
How can I achieve this operation with a lower complexity?
SessionsFilteredByDateAndErrors = SessionsFilteredByDate
.Where(i => sessionsWithErrorsNotFixed.Any(y => y == i.SessionId));