我需要你的帮助 我怎样才能将这个sql解释为linq:
SELECT FK_ClassId, LectureDays
FROM tbl_TimeTables
WHERE (FK_ClassId = 11)
group by fk_classid, lecturedays
having count(distinct Period) < 7
非常感谢任何帮助 添
答案 0 :(得分:0)
应该是这些方面的东西 (按ID分组,计算期间,适用于where子句,项目结果)
var query = from timetable in context.TimeTables
where timetable.ClassId == classId
group timetable by new
{
timetable.ClassId,
timetable.Period
} into groupings
let counter = groupings
.Select(p => p.Period)
.Distinct()
.Count()
where counter < 7
select new
{
ClassId = groupings.Key.ClassId,
Days = from grouping in groupings
select grouping.LectureDays
};
答案 1 :(得分:0)
from t in Tbl_TimeTables
where t.FK_ClassId == 11
group t by new
{
t.FK_ClassId,
t.LectureDays
} into groupings
let counter = groupings
.Select(p => p.Period)
.Distinct()
.Count()
where counter < 7
select new
{
ClassId = groupings.Key.FK_ClassId,
Days = (from grouping in groupings
select grouping.LectureDays).Distinct()
}
我只需要通过键将组更改为lecturedays而不是period,这会删除我得到的一系列结果。 非常感谢Dan