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 ?

macpak
  • 1,190
  • 1
  • 14
  • 28
  • [linq case sensitive](http://stackoverflow.com/questions/5104520/linq-case-sensitive) – Yuliam Chandra Aug 11 '14 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. – macpak Aug 12 '14 at 09:29
  • `var name = (username ?? string.Empty).ToLower(); var any = context.Users.Any(u => u.Name.ToLower() == name);` – Yuliam Chandra Aug 12 '14 at 09:38
  • 3
    Yeah, but this is a workaround. I am looking for an option built into EF/Npgsql. – macpak Aug 12 '14 at 10:58
  • No, there is no such built-in option. EF follows the default database collation setting. You can try request it [here](http://entityframework.codeplex.com/workitem/list/basic). 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](http://msdn.microsoft.com/en-us/data/dn469464.aspx) to add `COLLATE SQL_Latin1_General_CP1_CI_AS` query in the where clause (but this will be overkill). – Yuliam Chandra Aug 12 '14 at 11:57

0 Answers0