Is AsQueryable method departed in new Mongodb C# driver 2.0rc?

前端 未结 3 1429
小鲜肉
小鲜肉 2021-02-12 10:49

First of all I\'m new to MongoDb. In MongoDb C# driver 1.9.x, i can take collections as queryable with AsQueryable method like this.

        var db = client.Get         


        
3条回答
  •  鱼传尺愫
    2021-02-12 11:46

    I originally had the following using mongocsharp version 1.9x:

    public IQueryable SearchFor(Expression> predicate)
    {
        return _collection.AsQueryable()
                          .Where(predicate.Compile()).AsQueryable();
    }
    

    Was able to get the same results in version 2 using:

    public async Task> SearchFor(Expression> predicate)
    {
        return await _collection.Find(Builders.Filter.Where(predicate)).ToListAsync();
    }
    

    Hope it helps.

提交回复
热议问题