Multi-field queries using C# driver for MongoDB

后端 未结 1 860
旧巷少年郎
旧巷少年郎 2021-01-01 00:35

I\'m having trouble figuring out syntax for what I\'m trying to accomplish. As stated I\'m using the C# driver for MongoDB.

I have a User entity defined as



        
1条回答
  •  说谎
    说谎 (楼主)
    2021-01-01 01:10

    You can use Query.And() like this...

    var entityQuery = Query.And(
                          Query.EQ(e => e.Username, username.ToUpper()),
                          Query.EQ(e => e.Password, password)
                      );
    

    See CSharp Driver Tutorial

    Or you could do it LINQ style, see: CSharp Driver LINQ Tutorial

    This is also interesting too: How to rewrite a MongoDB C# LINQ with a Projection Requirement using a MongoCursor

    0 讨论(0)
提交回复
热议问题