sql to linq select d.DishShopID, d.DishName,d.DishPrice,d.DishImageUrl,AVG(c.CommentScore) as Comments from Dishes d left join Comments c on d.DishID=c.CommentDishID where d.DishShopID=5 group by d.DishName,d.DishPrice,d.DishImageUrl,d.DishShopID order by Comments desc
var query=from d in db.Dishes
join c in db.Comments
on d.DishID equals c.CommentDishID into lf
from c in lf.DefaultIfEmpty()
where d.DishShopID==5
group d by new {d.DishName,d.DishPrice,d.DishImageUrl,d.DishShopID} into g
let Cts=g.Average(x=>x.CommentScore)
orderby Cts descending
select new
{
g.Key.DishShopID,
g.Key.DishName,
g.Key.DishPrice,
g.Key.DishImageUrl,
Comment=Cts
};
------解决方案--------------------