加入后Linq过滤器

时间:2018-05-08 13:38:35

标签: linq

我在linq中加入了4个不同的列表。我需要在select new之前做一个过滤器。我很难搞清楚这一点。

var results2 = from st in this

               join currentGrowth in levels on new {st.Core, st.Grade } equals new {currentGrowth.Core, currentGrowth.Grade } into currentLevel
               from level in currentLevel.Where(a => st.Score >= a.MinScore && st.Score <= a.MaxScore).DefaultIfEmpty()

               join growthScores in ScoresGrowth on new { st.id, st.Core } equals new { growthScores.id, growthScores.Core } into gs
               from gscores in gs.Where(a => !a.Passed && !st.Passed && a.TestName != st.TestName).DefaultIfEmpty()

               join pastGrowth in levels on new { gscores?.Core, gscores?.Grade } equals new { pastGrowth?.Core, pastGrowth?.Grade } into pLevel
               from pastLevel in pLevel.Where(a => gscores.Score >= a.MinScore && gscores.Score <= a.MaxScore).DefaultIfEmpty()

               group new { st, gscores, level, pastLevel } by new { st.Division, st.School, st.Core }
               into testGroups

               select new
               {
                   Division = testGroups.Key.Division,
                   Core = testGroups.Key.Core,
                   School = testGroups.Key.School,
                   All_Total = testGroups.Count(),
                   All_PassCount = testGroups.Count(a => a.st.Passed),
                   All_Growth = testGroups.Count(a=> !a.st.Passed && (a.level?.Level > a.pastLevel?.Level) )
               };

我需要将以下过滤器应用于select中检索到的字段。有没有办法在select new之前执行此操作,或者必须将其应用于select new中的每个计算。除此之外还有很多其他内容。

!(st.SOA_LEP && !st.Passed && pastLevel.Level < level.Level)
 && !(st.SOA_Transfer && !st.Passed && pastLevel.Level < level.Level)

0 个答案:

没有答案