title: Dynamic expression for filter IQueryable
body: <p>I have a situation where I have just the property name (string) and the value by which desire filter.
  I need to filter the list to return <code>true</code> if any name repeated.</p>
  
  <p>Remembering that the filter should exclude it yourself. With expression like: <code>p =&gt; p.Id != currentId</code></p>
  
  <h1>Code</h1>
  
  <p>As the property is a string, I decided to create a Dynamic Expression to solve this problem.</p>
  
  <pre><code>[TestMethod]
  public void TestingExpression()
  {
      // Arrange
      var fix = new Fixture();
      var list = fix.Build&lt;User&gt;()
                      .With(p =&gt; p.Name)
                      .OmitAutoProperties()
                      .CreateMany(20).AsQueryable(); // Create IQueryable&lt;User&gt; with 20 users
  
      // Act 
      var currentId = 2;
      var uniquePropName = "Name";
      var uniqueValue = "{NotFoundValue}";
  
      // Expression: p =&gt; p.Id != currentId
      ParameterExpression pId = Expression.Parameter(typeof(int), "Id");
      ConstantExpression cId = Expression.Constant(currentId, typeof(int));
      BinaryExpression notCurrent = Expression.NotEqual(pId, cId);
      Expression&lt;Func&lt;int, bool&gt;&gt; NotCurrentExpr =
          Expression.Lambda&lt;Func&lt;int, bool&gt;&gt;(
              notCurrent,
              new ParameterExpression[] { pId });
  
      // Expression: p.{uniquePropName} == {uniqueValue}
      ParameterExpression pUnique = Expression.Parameter(typeof(string), uniquePropName);
      ConstantExpression cUnique = Expression.Constant(uniqueValue, typeof(string));
      BinaryExpression checkUnique = Expression.Equal(pUnique, cUnique);
      Expression&lt;Func&lt;string, bool&gt;&gt; CheckUniqueExp =
          Expression.Lambda&lt;Func&lt;string, bool&gt;&gt;(
              checkUnique,
              new ParameterExpression[] { pUnique });
  
  
      var exp = Expression.And(NotCurrentExpr, CheckUniqueExp);
  
      // Asset
      list.Provider.CreateQuery&lt;User&gt;(exp).ToList()
              .Should().HaveCount(19);
  
  }
  </code></pre>
  
  <h2>Question</h2>
  
  <p>The goal is to create a dynamic expression as: <code>query.Any(p =&gt; p.Id != id &amp;&amp; p.{Dynamic} == nome);</code></p>
  
  <p>But I do not know how to continue ..</p>
  
  <p>Thanks</p>