-1

I am trying to make an alphabetical comparison in LINQ but the expression cannot be compiled in SQL.

Any hint?

The suggested answer does not work. I get:

The LINQ expression '(Compare([f].str1, str2, Ordinal) < 0)' could not be translated and will be evaluated locally.

Update: I am using the PredicateBuilder found in http://www.albahari.com/nutshell/predicatebuilder.aspx

user2715109
  • 351
  • 6
  • 16

1 Answers1

2

you need to use string.Compare(...)

.Where(e => string.Compare(str1, str2, StringComparison.OrdinalIgnoreCase) < 0)
Matthew Whited
  • 22,160
  • 4
  • 52
  • 69
  • Actually the third argument doesn't matter, so `string.Compare(str1, str2)` is sufficient. – Ivan Stoev Feb 23 '16 at 21:00
  • 2
    It still does not like it: The LINQ expression '(Compare([f].str1, str2, Ordinal) < 0)' could not be translated and will be evaluated locally. – user2715109 Feb 23 '16 at 21:02
  • if you want more help you will need to include sample code such as the method body giving you problems. The issue seems to be in the way you are constructing your query. – Matthew Whited Feb 24 '16 at 14:16
  • I am using this class to construct my query: http://www.albahari.com/nutshell/predicatebuilder.aspx – user2715109 Feb 24 '16 at 19:54