I have a minor problem guys which I need some help. I have a Restaurant object which has the fields : districtId, dishId, foodCategoryId and restaurantName.
Based on my code below, I need to check from the districtId array input parameter if it has a match in the RestaurantTable. I have an idea I should use
districtId.ToList().Foreach( blah blah action )
but I am having a difficulty using it. Please advise. Thanks In advance.
My code snippet:
public IEnumerable<Restaurant> GetAllRestaurants(string restaurantName
, int[] districtId
, int dishId = 0
, int foodCategoryId = 0)
{
var q = RestaurantTable.Where(restaurants => restaurants.RestaurantName.Contains(restaurantName.ToLower().Trim())
| restaurants.DishId == dishId
| restaurants.FoodCategoryId == foodCategoryId
| "For each Id's in districtId check if it has a match in restaurants.DistrictId")
return q.ToList();
}
You can use
Contains():Also you want to use
||(logical OR) instead of|(binary OR)