Linq partial match in list?

前端 未结 1 472
臣服心动
臣服心动 2021-01-20 01:06

I have a list of partial strings that I need to match in a table. I\'m using PredicateBuilder.

var predicate = PredicateBuilder.False();
List<         


        
1条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-20 01:14

    You should change your code this way

    var predicate = PredicateBuilder.False();
    List names = new List();
    names.Add("test name"); 
    names.Add("test"); 
    foreach(string name in names)    
    {
        string temp = name;
        predicate = predicate.Or(n => n.Company.Contains(temp));
    }
    var results = (from n in Names 
        .AsExpandable()
        .Where(predicate)
        select(new{ n.Company}));
    

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