title: Check dates fall within range using Linq
body: <p>I'm currently working on something which requires me to check availability between two dates. My current methods aren't returning the expected result. For example, say I have the following reservations: </p>
  
  <ul>
  <li>13/04/2015 to 18/04/2015</li>
  <li>15/04/2015 to 20/04/2015</li>
  <li>10/04/2015 to 16/04/2015</li>
  </ul>
  
  <p>and I wish to view all reservations that are between 15/04/2015 to 16/04/2015. Visually, this might look like:</p>
  
  <pre><code>              15    16
        X________|_____|______X
                 |X____|_____________X
  X______________|____X|
                 |     | 
  </code></pre>
  
  <p>To get all the reservations that fall between these dates I am using:</p>
  
  <pre><code>public List&lt;ReservationClientModel&gt; GetReservationsByDateRange(int id, DateTime checkin, DateTime checkout)
      {
          var reservation = _repository.FindAllBy(x =&gt; 
              (x.StartDate &gt;= checkin &amp;&amp; x.EndDate &lt;= checkout) ||
              (x.StartDate &gt;= checkin &amp;&amp; x.StartDate &lt;= checkout) ||
              (x.EndDate &gt;= checkin &amp;&amp; x.EndDate &lt;= checkout)),
              y =&gt; y.RoomTypeNav)
              .ToList();
  
          return Mapper.Map&lt;List&lt;ReservationClientModel&gt;&gt;(reservation);
      }
  </code></pre>
  
  <p>Which is using:</p>
  
  <pre><code>public IEnumerable&lt;TEntity&gt; FindAllBy(Expression&lt;Func&lt;TEntity, bool&gt;&gt; predicate, params Expression&lt;Func&lt;TEntity, object&gt;&gt;[] includes)
      {
          var set = _dbSet.AsQueryable();
          set = includes.Aggregate(set, (current, include) =&gt; current.Include(include));
          return set.Where(predicate);
      }
  </code></pre>
  
  <p>This will only return the last two reservations though, and I believe this to be because it is checking for <code>&gt;=</code> and <code>&lt;=</code> on the dates, rather than checking that it falls within the range. I'm aware of using the SQL <code>BETWEEN</code> operator, but I was wondering if there is any way to do this using a Linq expression or from within C#? Ideally I would like to perform this as part of the EF Query as opposed to returning all reservations, then performing the operations on this list. </p>
  
  <p>Thanks.</p>