getting values from a var

Viewed 48

I set up two variables, and am trying to compare values from both. I set up a .Where(), where I try to compare the second var to the first. How do I get the values of the second var, inside a .Where()?

 var fail = securityContext.Attempts.Where(f => f.Date < from 
                                           && f.Date > to && f.Opened == false);
 var success = securityContext.Attempts.Where(s => s.Date < from 
                                          && s.Date > to && s.Opened == true);

 var nonSuspicious = fail.Where(n => n.Date < success.Any(d => d.Date);
1 Answers

You're using .Any() incorrectly. .Any() returns a boolean value, so your code is comparing n.Date with true/false, which doesn't make sense.

Try:

var nonSuspicious = fail.Where(n => success.Any(d => d.Date > n.Date));

This will then return records from fail where there are ANY success dates later than the fail date.

Related