title: How to configure LINQ request
body: <p>I have 2 tables:
  'AllowedDates'</p>
  
  <pre><code>- DayID int PK
  - Day datetime
  </code></pre>
  
  <p>'AllowedTimes'</p>
  
  <pre><code>- TimeID int PK
  - DayID int FK
  - Hour int
  - Minute int
  </code></pre>
  
  <p>also I have table 'Users':</p>
  
  <pre><code>- ID int PK
  - FirstName nvarchar(max)
  ...
  </code></pre>
  
  <p>and table 'UserDeniedTimes':</p>
  
  <pre><code>DayID int FK
  UserID int FK
  Hour int
  Minute int
  </code></pre>
  
  <p>I need to select users, which don't have deny time (record in UserDeniedTimes) for concrete DayID/Hour/Minute</p>
  
  <p>I try to do the following:</p>
  
  <pre><code>var result = from i in _dbContext.Users
  where i.UserDeniedTimes.All(
      p =&gt; (!p.AllowedDate.AllowedTimes.Any(
          a1 =&gt; a1.DayID == aTime.DayID
             &amp;&amp; a1.Hour == aTime.Hour
             &amp;&amp; a1.Minute == aTime.Minute
      ))
  )
  select new ...
  </code></pre>
  
  <p>it works correctly, but with one exception. If user has record in UserDeniedTimes for some day, but another time, this user is not selected too. For example, UserDeniedTimes has record:</p>
  
  <pre><code>DayID = 10
  UserID = 20
  Hour = 14
  Minute = 30
  </code></pre>
  
  <p>this user will be not selected if aTime has the following values:</p>
  
  <pre><code>DayID = 10
  Hour = 9
  Minute = 30
  </code></pre>
  
  <p>but will be selected if DayID = 11. Why?</p>
  
  <p>[ADDED]
  it works correctly when I limit only by day:</p>
  
  <pre><code>var result = from i in _dbContext.Users
  where i.UserDeniedTimes.All(
      p =&gt; (!p.AllowedDate.AllowedTimes.Any(
          a1 =&gt; a1.DayID == aTime.DayID
      ))
  )
  select new ...
  </code></pre>
  
  <p>but not works when I write:</p>
  
  <pre><code>var result = from i in _dbContext.Users
  where i.UserDeniedTimes.All(
      p =&gt; (!p.AllowedDate.AllowedTimes.Any(
          a1 =&gt; a1.Hour == 14
      ))
  )
  select new ...
  </code></pre>
  
  <p>why? What is difference between magic DayID and Hour ?</p>
  
  <p>[ADDED #2]</p>
  
  <pre><code>                     ((time == null) || i.UserDeniedTimes.All(p =&gt; 
                          //p.AllowedDate.AllowedTimes.Any(a1 =&gt; a1.DayID != 33) &amp;&amp; 
                          (p.AllowedDate.AllowedTimes.Any(a2 =&gt; a2.Hour != 14)
                          ))) &amp;&amp;
  </code></pre>
  
  <p>does not work</p>
  
  <pre><code>                     ((time == null) || i.UserDeniedTimes.All(p =&gt; 
                          p.AllowedDate.AllowedTimes.Any(a1 =&gt; a1.DayID != 33) &amp;&amp; 
                          //(p.AllowedDate.AllowedTimes.Any(a2 =&gt; a2.Hour != 14)
                          ))) &amp;&amp;
  </code></pre>
  
  <p>works</p>
  
  <p>why?</p>