2

How to add a string array

string[] BranchIds = {"1","2","3"}

inside the Linq Contains?

some thing like this i'm looking for

var a =_abc.GetRoutes(0).Where(n => n.BranchId.Contains(BranchIds[])).ToList();

Here the BranchId is a String in the model

Sribin
  • 195
  • 2
  • 14

2 Answers2

5

You are trying to check whether branchId of route contains array of ids (that will not compile). You should do the opposite - check whether ids array contains branchId of route:

var a =_abc.GetRoutes(0).Where(r => BranchIds.Contains(r.BranchId)).ToList();
Sergey Berezovskiy
  • 215,927
  • 33
  • 392
  • 421
1
var a =_abc.GetRoutes(0).Where(n => BranchIds.Contains(n.BranchId)).ToList();

Switch the order, for every BranchId in n check if it contained with in BranchIds

Ofir Winegarten
  • 8,588
  • 2
  • 17
  • 25