簡體   English   中英

如何使用Mongodb C#Driver進行謂詞搜索

[英]How to use predicate search using Mongodb C# Driver

如何在令人敬畏的MongoDB c#驅動程序上使用以下方法!????

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

例子很理想!

只需刪除Compile因為這會創建一個驅動程序無法轉換為mongo查詢的delegate

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

但它確實意味着謂詞表達式必須由MongoDB驅動程序翻譯。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM