.Equals string method not working in linq predicates

Jul 23, 2013 at 6:37 PM
Consider the following query:
context.Catalogs.Any(c => c.CatalogName.Equals(testCase, StringComparison.OrdinalIgnoreCase));
If the DBContext is pointing at a real database then this query evaluates correctly (that is, true if it finds a string match irrespective to case).

If I create the DBContext using the Effort EntitiyConnectionFactory then the query does NOT evaluate correctly.

The following works for both:
context.Catalogs.Any(c => c.CatalogName.ToLower() == testCase.ToLower());
Have I found a bug in Effort? I have a complete test solution for this that I can provide for you if you'd like. Please let me know. Thanks - love this framework and I hope you stick with it!
Jul 24, 2013 at 10:11 AM
I made some testing. However it seems the query that the Effort provider received does not include any string operations, just a plain comparison. Does the query do the same on the real database if you did not provide the OrdinalIgnoreCase option? I think case sensitivity is related to database collation.
Jul 24, 2013 at 12:42 PM
I'm not sure exactly what you're asking. Using a real database the first query I listed works as expected - that is, case is ignored, so "TEST" and "test" are equal. If I don't include the IComparer then of course "TEST" and "test" are not equal.
Jul 24, 2013 at 2:20 PM
Edited Jul 24, 2013 at 2:21 PM
Remove the OrdinalIgnoreCase option and run the query against your real database again.
string testCase = "test";
context.Catalogs.Any(c => c.CatalogName.Equals(testCase));
In my real SQL database, the Catalogs table only contained a single record, with CatalogName == "TEST". However, the query returned with true.

The default SQL database (Code First) compares string with case sensitivity OFF, so you do not even need to use the OrdinalIgnoreCase option. On the other hand Effort currently compares strings with case sensitively ON.
Jul 24, 2013 at 4:18 PM
Well, that's new to me, but you are correct about the .Equals method ignoring case by default in the EF context. Unfortunately, as you said, Effort does not. Can this be changed so that it accurately reflects EF?

Thanks for your attention to this matter.
Jul 24, 2013 at 4:57 PM
Yes, I will make case insensitivity as the default.
Nov 14, 2013 at 3:08 PM
Hi tamasflamich,

I ran into this same issue. I am using ToUpper() for my comparisons instead of StringComparison.OrdinalIgnoreCase.

While testing I tried .Equals without trying to match up the case thinking that you were going to make the comparison case insensitive but it doesn't work.

Did you finally make the string comparisons insensitive or is it still pending?

Nov 17, 2013 at 9:35 PM

In the moment my main priority is enabling custom data types and hot-fixing bugs. The next big thing will be probably this string comparison feature. Unfortunately until holidays my free time will be lacking, so I cannot promise any deadline.