gpt4 book ai didi

c# - 如何使用 Mongodb C# 驱动程序进行谓词搜索

转载 作者:可可西里 更新时间:2023-11-01 09:44:35 26 4
gpt4 key购买 nike

如何在很棒的 MongoDB c# 驱动程序上使用以下方法!????

public IList<TEntity>SearchFor(Expression<Func<TEntity, bool>> predicate)
{
return collection
.AsQueryable<TEntity>()
.Where(predicate.Compile())
.ToList();
}

示例将是理想的!

最佳答案

只需删除 Compile,因为这会创建一个 delegate,驱动程序无法将其转换为 mongo 查询:

public IList<TEntity>SearchFor(Expression<Func<TEntity, bool>> predicate)
{
return collection
.AsQueryable<TEntity>()
.Where(predicate)
.ToList();
}

但这确实意味着 谓词 表达式必须可由 MongoDB 驱动程序翻译。

关于c# - 如何使用 Mongodb C# 驱动程序进行谓词搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22922074/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com