title: Create a LinQ Expression with another Expression's Parameters
body: <blockquote>
    <h3>Vote my question to be closed</h3>
    
    <p>I have found a similar question and a really useful answer using
    <code>ExpressionVisitor</code> class (Link:
    <a href="https://stackoverflow.com/questions/14007101/how-can-i-convert-a-lambda-expression-between-different-but-compatible-models#14007103">How can I convert a lambda-expression between different (but compatible) models?</a>).
    Thank you all, I'm voting to my answer become closed as duplicate, please consider voting too.</p>
  </blockquote>
  
  <h2>Code</h2>
  
  <p>I'm developing a repository code that uses a Data Transfer Object, like the code below.</p>
  
  <pre><code>public class UsuarioRepositorio : IUsuarioRepository
  {
      private readonly MongoRepository&lt;UsuarioDto&gt; _Repository;
  
      public UsuarioRepository(string connectionString)
      {
          _Repositorio = new MongoRepository&lt;UsuarioDto&gt;(connectionString, "");
      }
  }
  
  public interface IUsuarioRepository
  {  
      IEnumerable&lt;T&gt; Select(Expression&lt;Func&lt;Usuario, bool&gt;&gt; predicate);
  }
  </code></pre>
  
  <ul>
  <li><p><strong>UsuarioDto</strong> is the data transfer object for the <strong>Usuario</strong> class, both inheriting from the interface <strong>IUsuario</strong>.</p></li>
  <li><p>The <strong>UsuarioRepository</strong> implements the <strong>IUsuarioRepository</strong> interface, and has a private member called _Repository, which belongs to the <code>MongoRepository&lt;UsuarioDto&gt;</code> type.</p></li>
  <li><p>The <strong>_Repository</strong> member has a method called <strong>Select</strong> which accepts an argument of type <code>Expression&lt;Func&lt;UsuarioDto, bool&gt;&gt;</code>.</p></li>
  <li><p>The <strong>IUsuarioRepository</strong> has a declared method called <strong>Select</strong> which accepts an argument of type <code>Expression&lt;Func&lt;Usuario, bool&gt;&gt;</code>.</p></li>
  </ul>
  
  <p><br></p>
  
  <h2>Problem</h2>
  
  <p>The problem is that I need to implement the <strong>Select</strong> method in <strong>UsuarioRepository</strong>, using the <strong>IUsuarioRepository</strong> method signature and passing to <strong>_Repository</strong> a new expression of <code>Expression&lt;Func&lt;UsuarioDto, bool&gt;&gt;</code> type, with the same parameters of <code>Expression&lt;Func&lt;Usuario, bool&gt;&gt;</code> argument.</p>
  
  <p>Basically I need a way to copy the expression parameters to a new expression of different type, knowing that the expressions has the same properties because they have the same interface inheritance. Something like this:</p>
  
  <pre><code>public IEnumerable&lt;Usuario&gt; Select(Expression&lt;Func&lt;Usuario, bool&gt;&gt; predicate)
  {
      Expression&lt;Func&lt;UsuarioDto, bool&gt;&gt; transferExpression = x =&gt; x != null;
      transferExpression = transferExpression .Update(predicate.Body, predicate.Parameters);
  
      return _Repository.Select(transferExpression ).ToList().Select(x =&gt; x.ToDomain());
  }
  </code></pre>
  
  <p><br></p>
  
  <h2>Questions</h2>
  
  <ul>
  <li>The <strong>Update</strong> method of <code>Expression</code> type does work like the code above?</li>
  <li>If it does not work, is there a way to copy expressions of different types, but with the same base/interface properties?</li>
  </ul>
  
  <p>Thank you very much!</p>