我正在使用linq查询从Appointment表中获取两个最近的约会。距离现在还不到365天。
当约会小于或等于365天时,我得到正确的值,但如果约会超过365天,我会收到错误。
我尝试使用n
,但不知道使用它的正确方法。能帮助我在正确的环境中使用它吗?
这是我的班级:
DefaultIfEmpty()
这是我的BO课程:
public SchedulingEligibility(ClassMember member)
{
int[] excludedStatuses = new int[]
{
(int) AppointmentStatusEnum.Cancelled,
(int) AppointmentStatusEnum.Deleted,
(int) AppointmentStatusEnum.Rescheduled,
(int) AppointmentStatusEnum.Missed,
(int) AppointmentStatusEnum.Pending
};
RecentAppointments = (from a in member.Appointments
orderby a.StartTime descending
where (!excludedStatuses.Contains((int)a.AppointmentStatusID) &
DateTime.Now.Subtract(a.StartTime).Days <= 365)
select a).Take(2).ToList();
if (RecentAppointments == null)
{
IsEligibleForDisplay = false;
}
else
{
IsEligibleForDisplay = true;
}
}
这是我从服务部门打来的电话:
public static SchedulingEligibility GetEligibility(Guid cmID)
{
using (PMCContext db = new PMCContext())
{
var cm = (from c in db.ClassMembers where c.ID == cmID select c)
.Include(x => x.Appointments)
.Include(x => x.Appointments.Select(y => y.lkp_AppointmentStatus))
.Include(x => x.Appointments.Select(y => y.Facility))
.Include(x => x.Appointments.Select(y => y.lkp_AppointmentType))
.Single();
return new SchedulingEligibility(cm);
}
}
这是结果的类型:
public SchedulingEligibility GetMemberEligibility(Guid cmID)
{
return ClassMemberBO.GetEligibility(cmID);
}