0
我有一个小问题,我需要一些帮助。我有一个Restaurant对象,其中包含字段:districtId,dishId,foodCategoryId和restaurantName。在Linq做一些小事
根据我的代码,我需要从districtId数组输入参数中检查它是否在RestaurantTable中匹配。我有一个想法,我应该使用
districtId.ToList().Foreach(blah blah action)
但我使用它有困难。请指教。提前致谢。
我的代码片段:
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();
}
感谢回答,让我试试那个。如果可以的话,你能解释一下那部分吗?或者我是否正确,如果districtId包含任何restaurant.DistrictId,它将返回true? – grayman
yey!有效!再次感谢:D – grayman