title: Abstraction with repository pattern
body: <p>I am building an application (a web api to be specific) and I want to implement the repository pattern to abstract the data access layer and prepare it for future changes.</p>
  
  <p>My goal is to make the repositories interfaces abstract enough to be able to implement every technology on top of them, starting from Native SQL Client (running sql command) to orm's like EF or dapper.</p>
  
  <p>I have read some articles about repositories and the interface of my generic repository looks something like that:</p>
  
  <pre><code>interface IRepository&lt;T&gt;
  {
      IEnumerable&lt;T&gt; FindAll();
  
      IEnumerable&lt;T&gt; FindBy(Expression&lt;Func&lt;T, bool&gt;&gt; predicate);
  
      T FindById(int id);
  
      void Add(T entity);
  
      void Remove(T entity);
  }
  </code></pre>
  
  <p>I want the method FindBy to accept a linq expression because the other option is making it accept native sql and that won't work too well with technologies like linq to entity of EF.</p>
  
  <p>The problem is that i also want to be able to implement a native sql repository on top of this interface and in order to implement a native sql repository, i need to run sql command, strings.
  In this interface i don't accept any sql command as string, i accept linq expressions, and the native sql client can't handle linq expressions (as far as i know).</p>
  
  <p>So my question is, how can i make this interface be compatible with any technology/orm/library/client/adapter, you get the idea...</p>
  
  <p>Thanks,
  Arik</p>