title: Trying to write a Generic Filter IQueryable
body: <p>I am trying to write a generic filter.
  This filter is being used for nearly every table in my DB. I need a generic Equals filter so I can apply to all my tables without repeating my code everywhere</p>
  
  <p>: I have the following code:</p>
  
  <pre><code>public static IQueryable&lt;T&gt; ApplyFilterModel&lt;T&gt;(this IQueryable&lt;T&gt; source, FilterDTO filterModel)
  {
      var type = typeof(T);
  
      if(filterModel.SelectedCompanyId != 0)
      {
          var property = type.GetProperty("iCompanyId");
          var parameter = Expression.Parameter(type, "p");
          var propertyAccess = Expression.MakeMemberAccess(parameter, property);
          var orderByExp = Expression.Lambda(propertyAccess, parameter);
          var resultExp = Expression.Call(typeof(Queryable), "Equals", new[] { type, property.PropertyType }, source.Expression, Expression.Quote(orderByExp));
          source = source.Provider.CreateQuery&lt;T&gt;(resultExp);
      }
  
      return source;
  }
  </code></pre>
  
  <p><code>type.GetProperty("iCompanyId");</code> The <code>iCompanyId</code> will always be an <code>Int32</code>.</p>
  
  <p>So when I am debugging and reach this line:</p>
  
  <pre><code>var resultExp = Expression.Call(typeof(Queryable), "Equals", new[] { type, property.PropertyType }, source.Expression, Expression.Quote(orderByExp));
  </code></pre>
  
  <p>I get this Error:</p>
  
  <p><img src="https://i.stack.imgur.com/38h7P.png" alt="enter image description here"></p>
  
  <p>What am I doing wrong here?</p>
  
  <p>I need to filter the Input IQueryable if <code>iCompanyId == filterModel.SelectedCompanyId</code> </p>
  
  <p>This is how I am calling the filter:</p>
  
  <pre><code>telematicDevices.ApplyFilterModel(model.FilterDTO);
  </code></pre>
  
  <p>Where telematicDevices is an IQueryable from the DB (Entity Framework)</p>