日期:2014-05-20  浏览次数:21057 次

Linq多对多查询求救
我这个需求是多对多  菜品和菜品分类 要根据菜品分类 查出所有菜品信息(包括菜品分类) 就是确定一条分类然后还要再加到查出每个菜品所有分类(这里的分类不止一个)代码如下:
var q = db.foodcategories.First(fc => fc.Id == categoryId);

             var q_a = from qq in q.foods
                       from p in db.pictures
                       //from qfc in q_fc
                       where p.FoodId==qq.Id
                       select new FoodModel
                       {
                           Id = qq.Id,
                           Name = qq.Name,
                           pictureUrl=p.Url,
                           Price = qq.Price,
                           Description = qq.Description,
                           MainIngredient = qq.MainIngredient,
                           MinorIngredient = qq.MinorIngredient,
                           Flavoring = qq.Flavoring,
                           Discount = qq.Discount,
                           Recommended = qq.Recommended