I have made a mistake in the code written but not in the logic
the correct code should be:
IPredicateExpression filter = new PredicateExpression();
filter .Add(PredicateFactory.CompareValue(PropertyAssignmentFieldIndex.Start,ComparisonOperator.LessEqual,endPeriod));
filter .Add(PredicateFactory.CompareValue(PropertyAssignmentFieldIndex.Finish,ComparisonOperator.GreaterEqual,startPeriod));
And To simplify it, your 4 logical OR-ed expressions were as follows, where Start & Finish are the 2 database fields storing holidays start and end dates.
And startPeriod & endPeriod are the period you wish to check for an overlapping holiday that part of it lies within.
// BeforeIn
Start <= startPeriod
Finish >= startPeriod
Finish <= endPeriod
// In
Start >= startPeriod
Finish <= endPeriod
// InAfter
Start >= startPeriod
Start <= endPeriod
Finish >= endPeriod
// Over
Start <= startPeriod
Finish >= endPeriod
So it's easier if considered which entities you don't want.
You don't want any entity that falls in the regions BeforeBefore & AfterAfter
i.e any entity that will start after the endperiod for sure will be out of the checked period
And also any entity that ended before the startperiod will be out of the checked period too.
//NOT WANTED CASE is the:
Start > endPeriod OR Finish < startperiod
Therefore the WANTED CASE is:
NOT (Start > endPeriod OR Finish < startperiod)
Which is:
Start <= endPeriod AND Finish >= startPeriod
If you have any entity in the database that satisfies the above expression, it will for sure satisfy one of your 4 regions.
Since in all of your 4 regions, this rule is valid.
This can be easily understood if you spot your 4 regions on a time line drawing.
Note: this is valid provided that Finish > Start and also endPeriod > startPeriod