Mongodb, linq driver. How to construct Contains with variable or statements

前端 未结 2 1735
予麋鹿
予麋鹿 2021-01-13 13:29

I\'m using the Mongo LINQ Driver for C#, works great.

Sorting a lot of properties but heres a problem I can\'t solve, its probably simple.

var identi         


        
2条回答
  •  一个人的身影
    2021-01-13 14:07

    To answer my own question ... The Mongo Sharp LINQ driver has an extension method called "In" which does exactly what I need.

    They have however implemented it in 1.5 so we can use the old way like: https://jira.mongodb.org/browse/CSHARP-462

     var list = new []{"10", "10"};
    
     search.Where(x => list.Contains(x.Id));
    

    But the version 1.5 package is not on nuget yet.

    However, this should work with the "In" extension that comes as a special surprise with the mongo-csharp-driver.

     search.Where(x => x.In(list));
    

提交回复
热议问题