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;
}
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With