Linq IN Operator

后端 未结 5 1690
北恋
北恋 2020-12-06 08:56

I\'ve tried searching for this but couldn\'t find examples that suited my situation.

I have this method for returning customers. How can I use the string array of co

相关标签:
5条回答
  • 2020-12-06 09:51

    You are backwards:

    return g.Customers.Where(x => customerCodesArray.Contains(x.customerCode)).ToList();
    
    0 讨论(0)
  • 2020-12-06 09:53

    I guess this is what you want

        return g.Customers.Where(x => customerCodesArray.Contains(x.customerCode)).ToList();
    
    0 讨论(0)
  • I think you need to reverse the Contains expression because you want to see if the array contains the customer code, not the other way around.

    Try this:

    return g.Customers.Where(x => customerCodesArray.Contains(x.customerCode)).ToList();
    
    0 讨论(0)
  • 2020-12-06 09:55

    Try the following code:

    return g.Customers.Where(x => customerCodesArray.Contains(x.customerCode)).ToList(); 
    
    0 讨论(0)
  • 2020-12-06 09:59

    Try

    return g.Customers.Where(x=>customerCodesArray.Contains(x.CustomerCode)).ToList();
    
    0 讨论(0)
提交回复
热议问题