I've got a string coming in like so:
'202,203,204,205,226,230,274'
I want to break this string down into an array of numbers and get back all the records with those Ids.
So far, I have:
string[] myArray = myString.Split(',');
int[] myIntArray = new int[myArray.Length];
for(int x = 0; x < myArray.Length; x++) {
myIntArray[x] = Convert.ToInt32(myArray[x].ToString());
}
model.Records = db.Records
.Where(q => q.RecordId.Contains(myIntArray)
.ToList();
It's complaining about Contains not working with ints. Am I get confused as to what Contains actually does?
Thanks in advance!
I think you want to do:
.Where(q => myIntArray.Contains(q.RecorId))
The way you have it, you're expecting the RecordId
to be an array (I'm assuming it's an int
?), whereas I think you want to take the single RecordId
and see if it is in the array of int
s.