我们的表结构如下所示:
appointmentID
1abc --------------->1
1abc (latest) ------------>2
1hjt
990aa
990aa
990aa (latest
DateTime start = DateTime.Now.AddDays(0);
DateTime end = DateTime.Now.AddDays(7));
List<JobCustomers> appointments = objectContext.JobCustomers.Where(
a => a.StartTime >= start && a.EndTime <= end && !string.IsNullOrEmpty(a.AppointmentId)).ToList();
foreach (JobCustomers appointmentItem in appointments) {
// HERE I WANT TO WRITE SOME CODE
-- WHEN WE ARE INSERTING NEW RECORD OF A SAME ID EX "1abc" IT MUST
COMPARE WITH LATEST RECORD "-----2>
}
我的要求:如果有超过 1 行具有相同的 id,那么我需要通过约会 id 带来最新记录,如下所示
List<JobCustomers> appointments = objectContext.JobCustomers.Where(
a => a.StartTime >= start && a.EndTime <= end && !string.IsNullOrEmpty(a.AppointmentId).**take(0**)).ToList();
简而言之:使用 LINQ 当我们插入具有相同 id 的新记录时,我们需要与最后插入的记录进行比较