Quote:
_dbContext.Semesters.Find(semesterViewModel.Semester.SemesterEndDate) < semesterViewModel.Semester.SemesterStartDate
The
Find
method finds the entity with the specified primary key, and returns it. That return value will be a
Semester
class instance, which could be
null
if no matching record was found.
You are then trying to test whether that
Semester
instance is less than a
DateTime
instance. But since you have not defined any way to compare a
Semester
instance to a
DateTime
, the code cannot compile.
It's not entirely clear what you are trying to do here, since the
Semester
is unlikely to have a
DateTime
for its primary key. At a complete guess, are you trying to ensure there are no overlapping semesters already in the database?
bool anyOverlappingSemesters = _dbContext.Semesters.Any(s =>
s.SemesterEndDate >= semesterViewModel.Semester.SemesterStartDate
&& s.SemesterStartDate <= semesterViewModel.Semester.SemesterEndDate);