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
外联如何表示?left join.
[解决办法]
参考:
Linq实现Left join
http://developer.51cto.com/art/200909/152189.htm
[解决办法]
http://msdn.microsoft.com/zh-cn/library/bb397895.aspx
[解决办法]
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 };
[解决办法]