我使用的是.NET 7,我有以下模型类:
public class MachineSchedule : BaseModel
{
public int MachineScheduleId { get; set; }
public EWeekDay WeekDay { get; set; }
public TimeSpan InitialProductionTime { get; set; }
public TimeSpan FinalProductionTime { get; set; }
public DateTime? UpdatedAt { get; set; }
#region Relationships
public virtual ICollection<MachineOperation>? MachineOperations { get; set; }
public virtual ICollection<Shift>? Shifts { get; set; }
public virtual ICollection<ScheduledStop>? ScheduledStops { get; set; }
#endregion
}
我想要进行查询过滤,例如,"Shift"模型类,所以我有:
machineScheduleDto = _context
.AsNoTracking()
.Include(m => m.Shifts.Where(s => s.Type == shiftType));
但由于我的关系是可选的,我收到以下警告:
参数可能为空引用实参.
我怎么才能解决这个问题?我知道如果我在类的声明中添加"Required",所有的问题都解决了,但我的关系真的是可选的,所以添加这个对我来说似乎是错误的.