Reputation: 5150
I have this query:
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 }
The above works but we have a version control system in place. I need to add in the ability to check if there is a version with a higher version that is not yet approved.
The above code looks for any document (d)
that is not marked as Deleted (DateDelete)
and it has been approved (DateApproved)
.
I need to add in the ability to check the Versions table to see if there is an unapproved version and if it has been marked as deleted or not.
After many attempts I cannot seem to get this to work.
d.IPACS_Versions.Where(v => v.revision > d.revision && v.dateDeleted == null)
Specifics:
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.
Upvotes: 0
Views: 52
Reputation: 149010
Try using Any
instead of 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 }
Upvotes: 1