我确信这是一个简单的,但我不能让它工作。这是我用作参考的 SQL 查询。我想用 LINQ 做同样的事情。
SQL:
select
schedulegroupslist.Schedule_Group_Key,
schedulegroupslist.Group_Name
from schedulegroupslist
inner join schedules on schedules.schedule_group_key = schedulegroupslist.Schedule_Group_Key
where schedules.Active = 1
and schedulegroupslist.Schedule_Count > 0
and schedulegroupslist.Active = 1
group by schedulegroupslist.Schedule_Group_Key
,schedulegroupslist.Group_Name
这是我认为可以解决问题的 linq,但我在组计划行上得到了一个空引用异常。
林克:
var included = from g in allGroups
join s in allSchedules
on g.ScheduleGroupKey equals s.GroupKey into sg
from schedules in sg.Where(s => s.Active == true
&& g.ScheduleCount > 0
&& g.Active == true).DefaultIfEmpty()
group schedules by
new { schedules.Key, schedules.ScheduleGroupName }
into schedulesgroup
select new { GroupName = schedulesgroup.Key.ScheduleGroupName,
ScheduleGroupKey = schedulesgroup.Key.Key };
对linq不太流利,所以也许有人可以告诉我一个更好的方法来完成我正在做的事情?