有人可以将这个简单的SQL语句转换为Linq吗?

时间:2011-02-17 17:11:58

标签: c# sql linq

select * 
    , (
    select AVG(RatingVal)  
    from Ratings 
    where Ratings.AppID = ID
    ) as average 
from Applications

1 个答案:

答案 0 :(得分:0)

var result = from r in Ratings
             group by r.AppID into rg
             from a in applications
             where a.ID = rg.Key
             select new {Application = a, AvgRating = rg.Avg(r=>r.RatingVal)};

没有测试过,但这应该可行。