title: Check if a bool? is True in Dynamic Lambda
body: <p>I'm doing a search form that has a few different options and have it all working except this one part.</p>
  
  <p>For reference I'm posting the entire method but the issue I'm having is trying to do a dynamic expression to check a <code>bool?</code> property. </p>
  
  <p>This line of code is where I'm having the problem...</p>
  
  <pre><code>call = Expression.IsTrue(propertyAccess); //TODO: Check if the property is true
  </code></pre>
  
  <p>As written it complains about <code>bool</code> to <code>bool?</code> conversion. If I change it to a <code>bool</code> instead of <code>bool?</code> it complains that <code>IsTrue is not a valid Linq expression</code>.</p>
  
  <p>Basically I want to do <code>x =&gt; x.UltrasonicTest == true</code> but don't know how to set that to a <code>MethodCallExpression</code>.</p>
  
  <p>Here is the short version of the code...</p>
  
  <pre><code>public ActionResult Search(List&lt;string&gt; selectedTests)
      {
          IQueryable&lt;Logbook&gt; logbooks;
          Expression lambdaStatus = null;
          Expression lambdaTests = null;
          Expression lambdaFinal = null;
  
          ParameterExpression parameter = Expression.Parameter(typeof(Logbook), "logbook");
          Expression call = null;
          PropertyInfo property = null;
  
          property = typeof(Logbook).GetProperty("UltrasonicTest");
  
          if (property != null)
          {
              MemberExpression propertyAccess = Expression.MakeMemberAccess(parameter, property);
              call = Expression.IsTrue(propertyAccess); //TODO: Check if the property is true
  
              lambdaTests = call;
          }
  
          lambdaFinal = Expression.And(lambdaStatus, lambdaTests);
  
          Expression&lt;Func&lt;Logbook, bool&gt;&gt; predicate = Expression.Lambda&lt;Func&lt;Logbook, bool&gt;&gt;(lambdaFinal, parameter);
          logbooks = db.Logbooks.Where(predicate);
  
          List&lt;Logbook&gt; filteredLogbooks = logbooks.OrderByDescending(x =&gt; x.DateEntered.Value).Take(50).ToList();
  
          return View("Index", filteredLogbooks);
      }
  </code></pre>