Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RavenDB Linq Invalid Operation .ToUpperInvariant()

Tags:

c#

linq

ravendb

I'm trying to use ToUpperInvariant() within a LINQ query with RavenDB. I'm getting an InvalidOperationException:

Cannot understand how to translate server.Name.ToUpperInvariant().

The query is below. What needs to happen in order for me to be able to match by name here? Is this possible within a query using RavenDB?

public ApplicationServer GetByName(string serverName)
{
    return QuerySingleResultAndCacheEtag(session => session.Query<ApplicationServer>()
        .Where(server => server.Name.ToUpperInvariant() == serverName.ToUpperInvariant()).FirstOrDefault())
        as ApplicationServer;
}

protected static EntityBase QuerySingleResultAndCacheEtag(Func<IDocumentSession, EntityBase> func)
{
    if (func == null) { throw new ArgumentNullException("func"); }

    using (IDocumentSession session = Database.OpenSession())
    {
        EntityBase entity = func.Invoke(session);
        if (entity == null) { return null; }
        CacheEtag(entity, session);
        return entity;
    }
}
like image 268
Bob Horn Avatar asked Jan 02 '12 16:01

Bob Horn


1 Answers

As the exception states, the server does not understand ToUpperInvariant(). As far as I know, RavenDB uses a custom LowerCaseKeywordAnalyzer, so by default queries are case-insensitive. See the RavenDB documentation on analyzers for more details.

like image 170
Thomas Freudenberg Avatar answered Oct 22 '22 23:10

Thomas Freudenberg