0

SQL式があります

select S.SpecialtyName, COUNT(distinct SUC.SiteUserId) as Subscribers
from   SiteUserContent SUC Inner join 
       Specialties S on SUC.SpecialtyId = S.SpecialtyId Inner join 
        SiteUser SU on SUC.SiteUserId = SU.SiteUserId
where SU.DeletedFlag = 0
group by S.SpecialtyName
Order by S.SpecialtyName

同じものに対応するLINQ式は何になりますか?

4

2 に答える 2

1
from suc in context.SiteUserContent
join s in context.Specialties on suc.SpecialtyId equals s.SpecialtyId
join su in context.SiteUser on suc.SiteUserId equals su.SiteUserId
where su.DeletedFlag == 0
select new { suc.SiteUserId, s.SpecialityName } into x
group x by x.SpecialityName into g
orderby g.Key
select new { 
    SpecialityName = g.Key, 
    Subscribers = g.Select(i => i.SiteUserId).Distinct().Count()
}

生成されるSQLは同じではありませんが、クエリ実行の結果は同じである必要があると思います。

于 2013-03-26T14:37:43.867 に答える
0
var results = contex.SiteUserContent
                    .Join(context.Specialties, suc => suc.SpecialtyId, s => s.SpecialtyId, (suc, s) => new { suc, s })
                    .Join(context.SiteUser, i = i.suc.SiteUserId, su => su.SiteUserId, (i, su) => new { suc = i.suc, s = i.s, su = su })
                    .Where(i => i.su.DeletedFlag == 0)
                    .GroupBy(i => i.s.SpecialtyName)
                    .Select(g => new {
                                     SpecialityName = g.Key,
                                     Subscribers = g.Select(i => i.suc.SiteUserId)
                                                    .Distinct()
                                                    .Count()
                                 })
                     .OrderBy(i => i.SpecialityName);
于 2013-03-26T14:47:03.883 に答える