How can I do a case insensitive string comparison (CONTAINS operator) with dotnet client?

I'm trying to do a case insensitive string comparison so far without success.

return (await graphClient.Cypher
.Match("(e:EntityNode)")
.Where((EntityNode e) => e.Name.ToLower().Contains(name.ToLower()))
.Return(e => e.As())
.ResultsAsync);

Contains + ToLower worked in Cypher but it is not working as expected in the dotnet client. Is there an attribute ou type I must include?

Hey Fernando,

To do what you want, you would have to do it like this:

return (await graphClient.Cypher
    .Match("(e:EntityNode)")
    .Where($"toLower(e.Name) CONTAINS {name.ToLower()}")
    .Return(e => e.As<EntityNode>()
    .ResultsAsync);

The problem is that there isn't a ToLower() overload handled in the client.

A few things I would consider if this is a frequent call:

  1. Pass name in as a parameter, already ToLower'd

i.e.

return (await graphClient.Cypher
    .Match("(e:EntityNode)")
    .Where("toLower(e.Name) CONTAINS $name")
    .WithParam("name", name.ToLower()) //You could do the ToLower outside
    .Return(e => e.As<EntityNode>()
    .ResultsAsync);
  1. Consider storing the name as a lower case property as well i.e.:

var name = name.ToLowerInvariant();

return (await graphClient.Cypher
    .Match("(e:EntityNode)")
    .Where((EntityNode e) => e.NameLowerCase.Contains(name))
    .Return(e => e.As<EntityNode>()
    .ResultsAsync);

I would choose option (2) as performance wise it will be fastest, and allows you to use auto parameterisation. Also - doing the name.ToLowerInvariant() outside of the actual query makes it clear the intent of that parameter.

All the best

Charlotte