向LINQ查询添加功能

时间:2013-09-16 22:07:51

标签: c# linq

我有这个问题:

from p in IPACS_Procedures
where !(from pd in IPACS_ProcedureDocs
       join d in IPACS_Documents on pd.DocumentID equals d.DocumentID
       where d.DateDeleted == null && d.DateApproved != null
       select pd.ProcedureID).Contains(p.ProcedureID)
select new { p.ProcedureID, p.Name }

上述工作但我们有一个版本控制系统。我需要添加检查是否存在尚未批准的更高版本的版本的功能。

上述代码会查找未标记为已删除document (d)且已被批准(DateDelete)的任何(DateApproved)

我需要添加检查Versions表的功能,以查看是否存在未批准的版本以及是否已将其标记为已删除。

经过多次尝试后,我似乎无法使其发挥作用。

d.IPACS_Versions.Where(v => v.revision > d.revision && v.dateDeleted == null)

具体细节:

d.DateDeleted must equal null to be valid
d.DateApproved must not be null to be valid

d will always have a record in IPACS_Versions but if the record in IPACS_Version 
has a higher revision than d.revision and if the higher version then dateDeleted 
must be null to be valid in the above list.

1 个答案:

答案 0 :(得分:1)

尝试使用Any代替Where

from p in IPACS_Procedures
where !(from pd in IPACS_ProcedureDocs
       join d in IPACS_Documents on pd.DocumentID equals d.DocumentID
       where d.DateDeleted == null && d.DateApproved != null &&
             d.IPACS_Versions.Any(v => v.revision > d.revision && v.dateDeleted == null)
       select pd.ProcedureID).Contains(p.ProcedureID)
select new { p.ProcedureID, p.Name }