title: Convert Expression<Func<DTOUser, bool>> predicate to Expression<Func<User, bool>> predicate
body: <p>I have a problem in Expression</p>
  
  <p>I have an Entity</p>
  
  <pre><code>public class User{ 
  public string Username{get;set;}
    public int PhoneNumber{get;set;}
    public string FIrstName{get;set;}
    public string LastName{get;set;}
  }
  </code></pre>
  
  <p>and I have a DTO</p>
  
  <pre><code>public class DTOUser{
    public string Username{get;set;}
    public int PhoneNumber{get;set;}
    public string FIrstName{get;set;}
    public string LastName{get;set;}
    }
  </code></pre>
  
  <p>Then I have a snippet code generic</p>
  
  <pre><code> public IList&lt;DTOUser&gt; SelectAll(Expression&lt;Func&lt;DTOUser, bool&gt;&gt; predicate)
      {
             using (var adc = _conn.GetContext())
          {   
         // what should I do ?? so i can convert Predciate to get all values from Users (Entity)   
  //it generates an error because predicate can't be cast into Entity User                    
   //   var users = adc.Users.All(predicate);
         }          
      }
  </code></pre>
  
  <p>I wanted to get a list of DTOUser by Passing LAMBDA Expression </p>
  
  <pre><code>accountrepo.SelectAll( user =&gt; user.firstname.equals ("sample"));
  </code></pre>
  
  <p>I have researched this issue and come to the conclusion that because DTOUser and User are of different type, it's difficult to cast the Expression from one type to another.</p>
  
  <p>One solution has been suggested by Jon Skeet:</p>
  
  <p><a href="https://stackoverflow.com/questions/729295/how-to-cast-expressionfunct-datetime-to-expressionfunct-object">How to cast Expression&lt;Func&lt;T, DateTime&gt;&gt; to Expression&lt;Func&lt;T, object&gt;&gt;</a></p>
  
  <p>but as this solution seems that I have to map each value from DTOUser to User doesn't this make it more complex as my DTOUser contains more than 15 properties.</p>
  
  <p>Can someone help me out?</p>