title: Map query expression from DTO to Entity Object
body: <p>I have inherited a code base that uses DTOs in the business layer, these are populated via a set of mappers from Entity Framework. This has some quite serious limitation in terms of querying so I am working on a new "optimised" querying service.</p>
  
  <p>My first issue is that I need to translate my LINQ query on my DTO to work with my Entity object but the calling context has no knowledge of the EF entities. Let's assume we can rely on the properties on each object having matching names.</p>
  
  <p>This is where I have got to in terms of stubbing out what I want:</p>
  
  <pre><code>   public static List&lt;TDataObject&gt; GetFiltered&lt;TDataObject(Expression&lt;Func&lt;TDataObject, TDataObject&gt;&gt; projection, Func&lt;TDataObject, bool&gt; filter)
     {
          // 1. translate the filter parameter to work with my equivalent Entity object
  
          // 2. build the EF query with the modified filter expression and also a Select() projection so we only return the properties we need. (this should generate an optimised SQL query under the hood)
  
          // 3. map the results from the EF query back onto my TDataObject and return (I already have AutoMapper maps in place for this)
     }
  </code></pre>
  
  <p>It is item 1 that I am struggling with so if anyone has any code examples for blogs posts for achieving this I'd appreciate it.</p>
  
  <p>Also if anyone has any alternate suggestions I'd be happy to hear them.</p>