linq表达式(实体)与subselect中的sum

时间:2014-08-28 22:32:33

标签: c# sql linq entity-framework entity

我是Entity的新手,对LINQ语句有疑问。

下面是我的代码,它出现在" TotalFoults"领域。他总是给出0.

任何人都可以帮助我,因为" TotalFoults"列的值大于零。

非常感谢。

var result = (from sr in db.StudentsResult
             join F in db.Fouls on sr.Enrollment equals F.Enrollment into F_join
             from F in F_join.DefaultIfEmpty()
             join S in db.Students on sr.Enrollment equals S.Enrollment into A_join
             from A in A_join.DefaultIfEmpty()
             where
               F.Day != null
             group new { sr, s } by new
             {
              sr.Enrollment ,
              sr.Name,
              sr.Number,
              sr.Classes,
              s.Discount
             } into g
             orderby
             g.Key.Classes,
             g.Key.Number,
             g.Key.Name
              select new frequencyMod()
               {
              Enrollment = g.Key.Enrollment ,
              StudentName = g.Key.Name,
              StudentFile= g.Key.Number,
              Classes = g.Key.Classes,
              TotalFoults = (from m0 in db.Foults
              where
              m0.Enrollment == g.Key.Enrollment 
              group m0 by new
              {
              m0.Enrollment 
                  } into a
                   select new
                   {
                   Total = a.Sum(p => p.Foults)
                   }).FirstOrDefault().Total
                   }).ToList();

0 个答案:

没有答案