c# - Querying MongoDB with List of IDs using Lambda Expression -


i'm hoping can me:

i'm using interface access data, find method is:

public iqueryable<t> find<t>(expression<func<t, bool>> expression) t : class, new()     {         return (iqueryable<t>) _db.getcollection<t>(typeof(t).name, writeconcern.acknowledged).asqueryable().where(expression);     } 

i'm trying build expression fetch objectids within list of objectids.

something like: r => r.id.containsany(list_of_ids); //where list_of_ids of type: list

i tried: r => r.id.containsany(new[] {id1, id2, id3}) //where id1, id2, id3 type objectid

but error containsany doesn't support parameter.

i hoping duplicate functionality of in statement in sql. goal want user collection contain list of products list of objectids , want query products collection , documents in user's list of product ids.

is possible? know i'm doing wrong?

thanks assistance! steve

btw: here send expression repository method:

public static list<product> getbyidlist(list<objectid> ids)     {         return (list<product>)repo.find<product>(r => r.id.containsany(ids));            } 

.containsany() meant used on array field.. use if .id array type.

for case you're looking .contains() or .in():

public static list<product> getbyidlist(list<objectid> ids) {     return (list<product>) repo.find<product>(r => ids.contains(r.id);        } 

which, coincidentally, equivalent to:

public static list<product> getbyidlist(list<objectid> ids) {     return (list<product>) repo.find<product>(r => r.id.in(ids));        } 

Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -