3

How can I perform a case insensitive search with contains on DocumnetDb? I'm using LINQ expression with IDocumentClient.

Here is an example of string comparision in LINQ:

u => u.Name.ToLower().Contains(searchParam.ToLower())

but I'm aware this is a full table scan.

thanks in advance

Nikhil Girraj
  • 1,135
  • 1
  • 15
  • 33
komluk
  • 437
  • 4
  • 18
  • Possible duplicate of [How to do a Case Insensitive search on Azure DocumentDb?](https://stackoverflow.com/questions/30512806/how-to-do-a-case-insensitive-search-on-azure-documentdb) – Imre Pühvel Mar 29 '18 at 11:59
  • 2
    It's not duplicated because I mentioned about LINQ not LOWER/UPPER function in DocumentDB – komluk Mar 29 '18 at 13:22
  • What do you think the `u.Name.ToLower()` would be translated to for documentDB execution? Leaving chosen syntax and question cosmetics aside, both problem and the solution are identical to the duplicate candidate. – Imre Pühvel Mar 29 '18 at 13:44
  • 1
    @ImrePühvel I don't think they are the same. Using LINQ or SQL in C# code is a design choice so the question is not a duplicate. – Nikhil Girraj Aug 08 '18 at 13:55
  • I think your query shall be working now – Venzentx Nov 12 '18 at 16:55
  • Before you enter into an evil early optimization, test your query and find out the RUs it consumes when executed against your DB. I'm currently using that query and I haven't found any issues with it, performance or financially wise. As you can see, this is what the generated SQL i get when i run that query. "SELECT VALUE root FROM root WHERE CONTAINS(LOWER(root[\"name\"][\"name\"]), \"searchParam\")"} – Robert Mrobo Mar 06 '21 at 16:31

0 Answers0