tags:

views:

63

answers:

1

I have the following statement:

List<string> tracks = new List<string> { "ABC", "DEF" };
var items = (from i in Agenda.AgendaSessions
  select i).Where(p => p.Tracks.Any(s => tracks.Contains(s.Code)));

this returns all sessions which track contains either ABC or DEF, now when I rewrite the statement like the following, it returns All sessions regardless, as if the clause always yeilds into true, can anyone shed any light on this please?

var items = from i in Agenda.AgendaSessions
  where i.Tracks.Any(s=> tracks.Contains(s.Code))
  select i;

Update

if there are other clauses within the where, does that affect the results?

+2  A: 

The two code snippets are equivalent, i.e. they should always produce the same results under all circumstances. Of course, that assumes that AgendaSessions, Tracks and .Contains() are what we expect them to be; if they are property getters/methods which have curious side-effects such as modifying the contents of tracks, then anything could happen.

In other words, without knowing what the rest of your code looks like, we cannot help you, because there is no semantic difference between the two code snippets.

Timwi
well then my question is, how is the structure of the statement in anyway affects the results? the AgendaSessions and its Tracks are both List<XElement>, and they both get loaded once on load of application so there is no processing that goes on once they reach this stage, tracks is the List<string> as you see it, doesnt get processed along the way at all... but anyway, i will prepare a much simpler test to confirm behavior... insights?
Ayyash
Ayyash