I was writing a simple LINQ query which compares rows of a table with itself. Simply put, there are two datagrids on a form, the first one shows some rows and the second one is filled whenever a row is selected in the first grid with the following condition:
Find those rows that have the same code as the selected and their reception time differs less than 30 second (I mean the reception time of shown rows in the second grid must be sooner than reception time of selected row).
I have written the following code:
Call_Log selected = (Call_Log)dataGrid1.SelectedItem;
var subData = from cLog in callLog
where cLog.Check_Create == 1 &&
EntityFunctions.DiffSeconds(selected.ReceptionTime,cLog.ReceptionTime) < 30 &&
selected.CustomerCode == cLog.CustomerCode &&
selected.CalledID == cLog.CalledID &&
selected.ID != cLog.ID
select cLog;
But it returns some rows which differ more than 30 seconds with the selected row. How can I fix this?
Comment:
In the above code, I need to have those rows (cLog) which differ less than 30 seconds from selected row.
Thanks
In case of
DiffSecondsreturn negative value more than 30 seconds, your validation return true.try compare after taking
Math.absas