6
我試圖在LINQ查詢中使用ToUpperInvariant()
與RavenDB。我發現了一個出現InvalidOperationException:RavenDB Linq無效操作.ToUpperInvariant()
能不知道如何翻譯server.Name.ToUpperInvariant()。
查詢如下。爲了讓我能夠在這裏與名字相匹配,需要發生什麼?這在使用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;
}
}
好吧,酷,我試圖通過轉換爲大寫比較,這甚至不是必要的。我只是嘗試了它,沒有轉換,它的工作。謝謝! – 2012-01-02 17:17:23
謝謝!我試圖做同樣的事情;根本不知道這件事。衛生署。 – Darryl 2013-03-08 22:14:50
也期待「編程語言像」的比較行爲,並遇到同樣的問題。我想我應該預料到「數據庫喜歡」比較,通常默認情況下會忽略大小寫。謝謝! – 2016-10-14 05:14:37