Overlapping records between two dates using Linq

前端 未结 1 1292
说谎
说谎 2021-01-19 10:05

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

相关标签:
1条回答
  • 2021-01-19 10:45

    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

    0 讨论(0)
提交回复
热议问题