3

I am using EF 6 + npgsql. I am trying to run a query that checks if a user with a given name (case insensitive) exists in db. I tried:

context.Users.Any(u => u.Name.Equals(username, StringComparison.InvariantCultureIgnoreCase)) 

however it doesn't work. Any help ?

5
  • linq case sensitive Commented Aug 11, 2014 at 10:55
  • 3
    Unfortunately, it doesn't help me much. I need a way to run a "case insensitive query" on postgresql database using EF. Commented Aug 12, 2014 at 9:29
  • var name = (username ?? string.Empty).ToLower(); var any = context.Users.Any(u => u.Name.ToLower() == name); Commented Aug 12, 2014 at 9:38
  • 3
    Yeah, but this is a workaround. I am looking for an option built into EF/Npgsql. Commented Aug 12, 2014 at 10:58
  • No, there is no such built-in option. EF follows the default database collation setting. You can try request it here. If you want to apply the case sensitive globally, you need to change the collation in the database level, something like SQL_Latin1_General_CP1_CI_AS. Or intercept the query to add COLLATE SQL_Latin1_General_CP1_CI_AS query in the where clause (but this will be overkill). Commented Aug 12, 2014 at 11:57

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.