0
I have the following model
public class AgendaExame
{
public int Id {get; set;}
public int PacienteId {get; set;}
public int ExameId {get; set;}
public DateTime Data {get; set;}
public DateTime ProximaData {get; set;}
}
The use of this model is to save the exam and date that was performed, and when will be the next exam (ProximaData
)
Following this saved information:
ID, PacienteId, ExameId, DATA, PROXIMADATA
1 1 1 01/01/2018 01/01/2019
2 1 2 01/01/2018 01/01/2019
3 1 1 31/12/2018 31/12/2019
When I filter between 01/01/2019
à 31/01/2019
I need to seek the tests that certain patients need to perform.
However, as we see in line 3, the patient performed the exam 1 day in advance, so his next date is only on the day 31/12
, then it should not be on the day 01/01
What I’ve tried so far is this:
var busca = db.AgendaExames.AsQueryable()
.Where(x =>
x.ProximaData != null &&
DbFunctions.TruncateTime(x.ProximaData ) >= model.Inicio &&
DbFunctions.TruncateTime(x.ProximaData ) <= model.Fim);
But this code only looks for the ones I have to perform, I still need to check if the patient did not take the exam in advance (as explained above)
Summary: Save exam and control when your next exam will be
What your query does is select all 'Scheduling Exams' that have 'Next Date' and also 'Date' between the end and the beginning of the date sent in the model. By what you tried to explain did not understand what you want, but will only return the 1st and 3rd record in this case if the date sent is 01/01/2018 to 31/12/2019.
– George Wurthmann
@Georgewurthmann Yes, I believe only with Where will I not succeed. But it is as I explained, seek the exams to perform based on Proximadata, but I have to validate also, if he does not have "Proximadata" in future months...
– Marcelo Dias
Can you build a clearer example? In your code you compared both Proximadata and Data, but in this last comment you are comparing only
– George Wurthmann
@Georgewurthmann ignore my code, he’s really wrong
– Marcelo Dias