I am trying the to query my Status Update repository using the following
var result = (from s in _dataContext.StatusUpdates
where s.Username == "friend1" && s.Username == "friend2" etc...
select s).ToList();
Instead of using s.Username == "friendN" continuously is there anyway I can pass a list or array or something like that rather that specifying each one, or can I use a foreach loop in the middle of the query.
Thanks
If you only need to check whether the
Usernameproperty has some specified value, you can create a list of the values and then use method such asAllorAnyto check if some condition holds for any/all elements of the array.Your example looks a bit suspicious though – the user name
s.Usernamecannot be equal to multiple different strings. Did you want to check whether it is equal to any of the (specified) names? That could be written like this:This returns all status updates such that the
Usernameproperty is equal to any of the specified friend names (specified as an array, but you could use anyIEnumerable<string>).