对于标题不清楚的原谅,不能想出任何更好的方式来表达它。
我有2个表,User和Appeal。
这是该过程的工作方式:
以下是我到目前为止提出的声明,我试图实现上述目标。
(from user in db.Users
where user.Roles.Any(r => r.RoleId == roleId)
where !db.Appeal.Any(y => y.PatientId == user.Id) // if no record found in appeal
|| // or if there's a record
(db.Appeal.OrderByDescending(a => a.Time).FirstOrDefault().PatientId == user.Id
&& db.Appeal.Any(a => a.PatientId == user.Id && a.IsApprove == 2))
// but only if the latest request is rejected, show back up
// in the user list again so it can be requested again
select new Patient {
PatientId = user.Id,
PatientName = user.FullName,
UniqueId = user.UniqueId
}).OrderBy(x => x.PatientId);
答案 0 :(得分:0)
最后解决了这个问题。
nameQuery = (from user in db.Users
where user.Roles.Any(r => r.RoleId == roleId)
where !db.Appeal.Any(y => y.PatientId == user.Id) // if no record found in appeal
||
db.Appeal.OrderByDescending(x => x.Time).FirstOrDefault(p => p.PatientId
== user.Id).IsApprove == 2
// or got appeal, but the latest result is rejected
select new Patient {
PatientId = user.Id,
PatientName = user.FullName,
UniqueId = user.UniqueId
}).OrderBy(x => x.PatientId);
更改
(db.Appeal.OrderByDescending(a => a.Time).FirstOrDefault()。PatientId == user.Id &安培;&安培; db.Appeal.Any(a => a.PatientId == user.Id&& a.IsApprove == 2))
到
db.Appeal.OrderByDescending(x => x.Time).FirstOrDefault(p => p.PatientId == user.Id).IsApprove == 2