0

我是一个 SQL 迷,EF 的语法对我来说并不直观。

我有一张餐厅桌和一张食物桌。我想要那些食物的类型包含在字符串列表类别中的餐馆和食物。这是一些大致代表我想要的SQL。

SELECT r.*, f.*
FROM Restaurant R
  JOIN food f on f.RestaurantID = r.RestaurantID
WHERE f.Type IN ("Awesome", "Good", "Burrito")

这是我想转换成该 SQL 的代码。

List<string> types = new List<string>() { "Awesome", "Good", "Burrito"};
var dbrestaurants = from d in db.Restaurants
                    .Include("Food")
                    //where Food.Categories.Contains(types)//what to put here?
                    select d;
4

3 回答 3

1

尝试

var restaurants = db.Restaurants.Where(r => types.Contains(r.Food.Type));
于 2012-04-23T22:00:36.327 回答
0
where Food.Categories.Any(c => types.Contains(c.Name))
于 2012-04-23T21:48:31.750 回答
0

尝试这个:

var dbRestaurants = 
from r in db.Restaurants
join f in db.Foods on r.RestaurantId equals f.RestaurantId
where types.Any(foodType => foodType == f.Type)
select r;
于 2012-04-24T14:08:30.833 回答