title: Null reference exception being thrown in EF LINQ query if-clause
body: <p>I couldn't find the exact words to explain what's happening, so if this is a duplicated question, I apologize.</p>
  
  <p>I tried to do a quite simple AND condition if-clause inside a LINQ Query, in order to check if an object is null and then verify if its property is equal or not the column I wanted to compare. </p>
  
  <p>The code: </p>
  
  <pre><code>public IEnumerable&lt;Plan&gt; GetPlans(Plan plan)
      {
          return _context.Plans.Where(e =&gt;
              e.Situation == plan.Situation &amp;&amp;
              e.Notes.Contains(plan.Notes) &amp;&amp;
              (plan.Excercise != null &amp;&amp; plan.Exercise.Year &gt; 0 ? e.Exercise.Year == plan.Exercise.Year: true)).ToList();
      }
  </code></pre>
  
  <p>I've already done this kind of check a dozen times before in .NET 4.5, without having any kind of issue.</p>
  
  <p>But now, in the first .NET Core 2.0 project I'm working on, I had the following error:</p>
  
  <pre><code>An exception was thrown while attempting to evaluate a LINQ query parameter expression. To show additional information call EnableSensitiveDataLogging() when overriding DbContext.OnConfiguring.
  </code></pre>
  
  <p>The inner exception is clearer: <strong>NULL REFERENCE EXCEPTION</strong>.</p>
  
  <p>After some tests, I found out that the error happens when plan.Exercise comes null, even if I try to avoid the exception by checking at first if it's null or not.</p>
  
  <p>If I try to do the same check directly in Immediate Window, it returns "false", as it should be. </p>
  
  <p>Am I missing something here? It could be an EF bug? Any particular reason why this works in .NET 4.5, for example, and not in .NET Core 2.0?</p>
  
  <p>Thanks in advance.</p>
  
  <p>UPDATE</p>
  
  <p>Ivan's solution did the job:</p>
  
  <p><em>Rewrite ? : constructs with equivalent ||</em> </p>
  
  <pre><code>plan.Excercise == null || plan.Exercise.Year &lt;= 0 || e.Excercise.Year == plan.Exercise.Year
  </code></pre>