在Linq中为每个人做一些小调

在Linq中为每个人做一些小调,linq,Linq,我有个小问题,伙计们,我需要一些帮助。我有一个餐馆对象,它有以下字段:districtId、dishId、foodCategoryId和restaurantName 根据下面的代码,我需要从districtId数组输入参数检查RestaurantTable中是否有匹配项。我有一个想法,我应该使用 districtId.ToList().Foreach( blah blah action ) 但是我使用它有困难。请告知。提前谢谢 我的代码片段: public IEnumerable<Re

我有个小问题,伙计们,我需要一些帮助。我有一个餐馆对象,它有以下字段:districtId、dishId、foodCategoryId和restaurantName

根据下面的代码,我需要从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();
}
public IEnumerable GetAllRestaurants(string restaurantName)
,int[]地区ID
,int dishId=0
,int foodCategoryId=0)
{
var q=RestaurantTable.Where(restaurants=>restaurants.RestaurantName.Contains(RestaurantName.ToLower().Trim())
|DishId==DishId
|restaurants.FoodCategoryId==FoodCategoryId
|“对于districtId中的每个Id,请检查其在餐厅中是否匹配。districtId”)
返回q.ToList();
}
您可以使用
Contains()


您还想使用
|
(逻辑或)而不是
(二进制或)

谢谢您的回答,让我试试这个。如果可以的话,你能解释一下那部分吗?或者我是对的,如果districtId包含任何restaurant.districtId,它将返回true?
    var q = RestaurantTable.Where(restaurant => restaurant.RestaurantName.Contains(restaurantName.ToLower().Trim())
                                 || restaurant.DishId == dishId
                                 || restaurant.FoodCategoryId == foodCategoryId
                                 || districtId.Contains(restaurant.DistrictId))