title: How to use MethodInfo and lifttonull in Expression equality on c#
body: <p>I'm trying to use Expression.NotEqual() (<a href="https://docs.microsoft.com/en-us/dotnet/api/system.linq.expressions.expression.notequal?view=netcore-3.1" rel="nofollow noreferrer">here</a>)</p>
  <p>But I can't understand how to use the methodInfo.</p>
  <p>I'm trying to make a comparison to a possible bool?.</p>
  <p>This is the property that I want to evaluate, which was added to database after release (creating null's as well as true and false:</p>
  <pre><code>public bool? Deactivated { get; set; } = false;
  </code></pre>
  <p>I'm using a working expression builder with generic that accepts parameters sent in a object that has a List of WhereParameters like below:</p>
  <pre><code>List&lt;WhereParameters&gt; whereList = new List&lt;WhereParameters&gt;();
  
          whereList.Add(new WhereParameters
          {
              field = &quot;ID&quot;,
              field_Value_Relation = &quot;notEqual&quot;,
              value = Guid.Empty
          });
          whereList.Add(new WhereParameters
          {
              field = &quot;Deactivated&quot;,
              field_Value_Relation = &quot;notEqualorNull&quot;, //orNull =&gt; nullable
              value = true
          });
  </code></pre>
  <p>These parameters are used in the builder:</p>
  <pre><code> public List&lt;M&gt; getExpression(QueryParameters&lt;M&gt; QueryParams)
      {
  
          
  
          //GET TYPE FROM GENERIC M
          Type modelType = QueryParams.modelType;
  
  
          //QUERY DB with GENERIC TYPE
          IQueryable&lt;M&gt; queryableData = (IQueryable&lt;M&gt;)QueryParams.db.Set(modelType);
  
          // Compose the expression tree that represents the parameter to the predicate.  
  
          //CREATE EXPRESSION PARAMETER
          ParameterExpression pe = Expression.Parameter(typeof(M), &quot;param&quot;); 
  
          // Create an expression tree that represents the expression 
          //if (QueryParams.whereParameters != null &amp;&amp; QueryParams.whereParameters.Count &gt; 0)
          //{
  
              int w = 0;
          foreach (WhereParameters whereParam in QueryParams.whereParameters) { 
          //BLOCK A.1 WHERE
          //Create Property on the Left of equality
          Expression left1 = Expression.Property(pe, whereParam.field.ToLower());
          //Create Property on the right of equality
          Expression right1 = Expression.Constant(whereParam.value);
  
              //Expresses the relation between left and right
  
              //Expression e1;
                  switch (whereParam.field_Value_Relation)
                  {
                      case &quot;notEqualOrNull&quot;:
                          predicateBody = Expression.NotEqual(left1, right1, true , ????????);
                          break;
                  }
  }
  </code></pre>
  <p>It is throwing a System.InvalidOperationException: The binary operator NotEqual is not defined for the types 'System.Nullable`1[System.Boolean]' and 'System.Boolean'.</p>
  <p>I don't know how to make this work with nullables. I understood the islifted param, but can't manage to understand what to send in the last parameter of Expression.NotEqual, as MethodInfo. Can someone please show me examples on how this can be done?</p>