views:

125

answers:

1

I cant understand why resultSet2 is empty! Only the first assert passes!

List<Tree> resultSet1 = this.datacontext.Trees.Where(t=>t.RiskRating.Contains("bad")).ToList();

Assert.IsTrue(resultSet1.count() == 3);


List<Tree> resultSet2 = this.datacontext.Trees.ToList().Where(t=>t.RiskRating.Contains("bad")).ToList();

Assert.IsTrue(resultSet2.count() == 3);

Thanks!

Ashley

+3  A: 

What does this.datacontext.Trees.ToList().Count() return?

Could it be something to do with your collation back at the database? The first example will convert the Contains("bad") method back to SQL, which might be case insensitive and return rows that contain "BAD" or "Bad". The second example wouldn't be case sensitive.

It'd be interesting to see what the values for RiskRating are back in the database, and what the SQL query getting executed looks like.

Matt Hamilton
Ah you're right - it came down to case sensitivity!Thanks Matt!
Ash Kim
Do you know of anyway to to a case insensitive Contains on an ObjectQuery?
Ash Kim
Do a ToLower on the variable before hand...
Ash Kim