Original
I don’t get why the Where() clause doesn’t give me the right results in the last example.
It isn’t any different is it? Why does C# behaves differently?
transactions = IEnumerable<Transaction> //pseudocode
//This works: It gives me the transaction I need.
DateTime startDate = DateTime.Parse(parameter.Constraint);
transactions = transactions.Where(T => T.date >= startDate);
//This doesn't work... No actual code changed, only the way of writing it...
//I get 0 results.
transactions = transactions.Where(T => T.date >= DateTime.Parse(parameter.Constraint));
Edit
Ok, it is indeed relevant to mention that transactions is loaded using Entity Framework.
transactions = this.db.Include("blablabla").OrderByDescending(T => T.date);
Maybe that’s why it’s doing weird? Because of the way Entity Linq works?
The only way this could actually be happening is if you were modifying
parameterorparameter.Constraintsomehow while you’re enumerating throughtransactions. So if you’re not doing that, look at whether you’re actually observing what you think you’re observing.In principle, this should work fine.
EDIT: One obvious way you could be confused about your observation is if you didn’t check the results of (actually evaluate) the lazy
Whereenumeration until later on, whenparameterhad changed. If you put aToArrayon the end to evaluate it immediately, you might find that it “magically” fixes itself.