Dynamic LINQ on IEnumerable?

前端 未结 2 628
野性不改
野性不改 2021-01-01 18:37

Say i need to filter a generic list with a dynamic query (List l; var x = l.Where(*dynamic query*))

How would i do this using LINQ? (Curre

2条回答
  •  旧巷少年郎
    2021-01-01 19:13

    Assuming you mean a string-based query: the dynamic LINQ library will work fine; just call .AsQueryable() first:

    string s = *dynamic query*
    var qry = l.AsQueryable().Where(s);
    

    This gives you an IQueryable wrapper around your list, which provides access to the dynamic LINQ extension methods.

提交回复
热议问题