首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

sql to linq解决办法

2012-09-10 
sql to linqselect d.DishShopID, d.DishName,d.DishPrice,d.DishImageUrl,AVG(c.CommentScore) as Commen

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
[解决办法]

C# code
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          };
[解决办法]
探讨

C# code

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
……

[解决办法]
探讨

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.Di……

热点排行