title: c# Repository pattern and where lambdas, how to convert type
body: <p>I'm trying to build an Entity framework abstract repository with data transfer objects and separate data providers. We need to be able to switch between oracle, sql server and azure sql depending on the install.</p>
  
  <p>The end repository returns DTO's to the consuming code. Get, Update and delete are working fine. The issue I'm having is with the lambdas for where clauses etc. The generic repository is unaware of the actual Entity object from the data provider so I can't create a where lambda.</p>
  
  <p>P.S. Using AutoMapper to convert between Entity and DTO</p>
  
  <pre><code>//Repository base
  public class Repository&lt;TEntity&gt; : IDisposable, IRepository&lt;TEntity&gt; where TEntity : class, IEntity
  {
      public virtual IList&lt;TEntity&gt; GetList(Func&lt;TEntity, bool&gt; where, params Expression&lt;Func&lt;TEntity, object&gt;&gt;[] navigationProperties)
      {
          List&lt;TEntity&gt; list;
  
          IQueryable&lt;TEntity&gt; dbQuery = Context.Set&lt;TEntity&gt;();
  
          //Apply eager loading
          foreach (Expression&lt;Func&lt;TEntity, object&gt;&gt; navigationProperty in navigationProperties)
              dbQuery = dbQuery.Include&lt;TEntity, object&gt;(navigationProperty);
  
          list = dbQuery
              .AsNoTracking()
              .Where(where)
              .ToList&lt;TEntity&gt;();
  
          return list;
      }
  }
  
  //Implementing repository where T is the entity from the EF model
  public class UserRepository&lt;T&gt; : IUserRepository, IUnitOfWork
      where T : class, IEntity
  {
      public Repository&lt;T&gt; Base { get; private set; }
  
      public UserRepository(DbContext context)
      {
          Base = new Repository&lt;T&gt;(context);
      }
  
      public List&lt;UserAccountDTO&gt; GetList(Expression&lt;Func&lt;UserAccountDTO, bool&gt;&gt; where)
          {
              T obj = SupportedRepos.DTOMapper.Map&lt;T&gt;(where.Parameters[0]);
                  /* HOW CAN I CONVERT THE FUNC&lt;&gt;? */
                  //Base.GetList();
                  return null;
          }
      }
  
  public void TestMethod1()
  {
      var dbtypeFromConfig = RepoEF.Setup.StorageType.SQLServer;
  
      using (var repo = RepoEF.Setup.SupportedRepos.Create(dbtypeFromConfig))
      {
          //WORKS FINE, CHANGES AND UPDATES
          var source = repo.Get(3);
          source.LookupId = 111111;
          repo.Add(source);
  
          //CAN'T CREATE WHERE BECAUSE UserRepository&lt;T&gt; ONLY SEES IEntity
          repo.GetList(x =&gt; x.UserAccountId == 3);
      }
  }
  </code></pre>
  
  <p>Is it possible to build a Func&lt;> to pass to the base Repository. </p>
  
  <p>If not any ideas how I change the design to achieve what I need?</p>