2012-01-20 5 views
0

私は助けが必要な小さな問題の人がいます。私はフィールドがあるレストランオブジェクトを持っています:districtId、dishId、foodCategoryId、そしてrestaurantName。Linqで少しずつやっています

以下のコードに基づいて、RestaurantTableに一致するものがあれば、districtId配列の入力パラメータからチェックする必要があります。私は使用すべきアイデアを持っています

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(); 
} 

答えて

1

あなたはContains()を使用することができます。

var q = RestaurantTable.Where(restaurant => restaurant.RestaurantName.Contains(restaurantName.ToLower().Trim()) 
           || restaurant.DishId == dishId 
           || restaurant.FoodCategoryId == foodCategoryId 
           || districtId.Contains(restaurant.DistrictId)) 

はまた、あなたの代わりにのために|(バイナリOR)

+0

感謝の||(論理和)を使用したいです答え、それを試してみましょう。もしそうなら、あなたはその部分を説明できますか?または、districtIdにrestaurant.DistrictIdのいずれかが含まれていれば、それはtrueを返しますか? – grayman

+0

yey!出来た!再度ありがとう:D – grayman

関連する問題