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