Is there a pattern using Linq to dynamically create a filter?

后端 未结 4 788
忘了有多久
忘了有多久 2020-11-27 06:07

Is there a pattern using Linq to dynamically create a filter?

I have the need to create custom filtering on a list, in the past I would just dynamically create the S

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-27 06:43

    something like this?

    var myList = new List { "a","b","c" };
    var items = from item in db.Items
                where myList.Contains(item.Name)
                select item;
    

    that would create a sql statement like

    SELECT * FROM Items [t0] where Name IN ('a','b','c')
    

提交回复
热议问题