title: How can I use Entity Framework 6 and my repository to delete multiple records?
body: <p>I am using Entity Framework 6 and I have a repository looking like the following with the Add and Update methods removed to make it shorter:</p>
  
  <pre><code> public class GenericRepository&lt;T&gt; : IRepository&lt;T&gt; where T : class
  {
      public GenericRepository(DbContext dbContext)
      {
          if (dbContext == null) 
              throw new ArgumentNullException("An instance of DbContext is required to use this repository", "context");
          DbContext = dbContext;
          DbSet = DbContext.Set&lt;T&gt;();
      }
  
      protected DbContext DbContext { get; set; }
  
      protected DbSet&lt;T&gt; DbSet { get; set; }
  
      public virtual IQueryable&lt;T&gt; Find(Expression&lt;Func&lt;T, bool&gt;&gt; predicate)
      {
          return DbSet.Where&lt;T&gt;(predicate);
      }
  
      public virtual IQueryable&lt;T&gt; GetAll()
      {
          return DbSet;
      }
  
      public virtual T GetById(int id)
      {
          //return DbSet.FirstOrDefault(PredicateBuilder.GetByIdPredicate&lt;T&gt;(id));
          return DbSet.Find(id);
      }
  
      public virtual void Delete(T entity)
      {
          DbEntityEntry dbEntityEntry = DbContext.Entry(entity);
          if (dbEntityEntry.State != EntityState.Deleted)
          {
              dbEntityEntry.State = EntityState.Deleted;
          }
          else
          {
              DbSet.Attach(entity);
              DbSet.Remove(entity);
          }
      }
  
      public virtual void Delete(int id)
      {
          var entity = GetById(id);
          if (entity == null) return; // not found; assume already deleted.
          Delete(entity);
      }
  }
  </code></pre>
  
  <p>In my controller I call the repository like this:</p>
  
  <pre><code>    public HttpResponseMessage DeleteTest(int id)
      {
          Test test = _uow.Tests.GetById(id);
          if (test == null)
          {
              return Request.CreateResponse(HttpStatusCode.NotFound);
          }
          try
          {
              _uow.Tests.Delete(test);
              _uow.Commit();
              return Request.CreateResponse(HttpStatusCode.OK);
          }
          catch (Exception ex)
          {
              return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex);
          }
      }
  </code></pre>
  
  <p>This works for a single test but how can I delete for example all tests that have an examId column value of 1 being
  that examId is one of the columns in the Test table.</p>