In my application a user can delegate another user to approve orders.
What I need to validate, is that there are no circular references so if User A
is
Can't you simply do
var doesOverlapExist = Session.QueryOver<DelegateOrderApproval>()
.Any(x =>
x.DateFrom > DateTime.Now &&
delegateOrderApproval.DelegatedUser.UserId == x.DelegatorUser.UserId &&
x.DateFrom <= delegateOrderApproval.DateTo &&
x.DateTo >= delegateOrderApproval.DateFrom);
or if you don't have any, replace with
Where(x=> blabla).Count() >0
overlap check logic : Determine Whether Two Date Ranges Overlap