mongodb中字符串之间的比较抛出InvalidOperationException

时间:2017-10-09 07:31:38

标签: mongodb asp.net-core mongodb-query

我正在尝试比较mongodb中的字符串,但它会引发异常。

我的代码是:

public WhiteBlackList GetWhiteBlackListByHash(string fileHashSHA256)
{
    try
    {
        IQueryable<WhiteBlackList> query = _mongoDbHelper.WhiteBlackList.AsQueryable();
        query = query.Where(list =>
                list.FileHashSHA256.ToLower().Equals(fileHashSHA256.ToLower()));
        return query.FirstOrDefault();
    }
    catch (Exception e)
    {
        _log.Error($"Error while getting WhiteBlackList({fileHashSHA256})", e);
        throw new StateRepositoryException(e.Message);
    }
}

异常消息是:{document}{FileHashSHA256}.ToLower() is not supported.

我试着像这样比较:

query = query.Where(list =>
                list.FileHashSHA256.Equals(fileHashSHA256, StringComparison.InvariantCultureIgnoreCase));

但它也会抛出异常。

0 个答案:

没有答案