How can I use Entity Framework 6 and my repository to delete multiple records?

asp.net-mvc entity-framework entity-framework-6

Popular Answer

In your generic repository class, you may add another remove function, as seen below:

    public virtual void Delete(Expression<Func<T, bool>> predicate)
    {
        IQueryable<T> query = DbSet.Where(predicate).AsQueryable();
        foreach (T obj in query)
        {
            DbSet.Remove(obj);
        }
    }

If you do, it will delete all records that match the criteria listed below.Id equalsid .

  _uow.Test.Delete(n => n.Id = id)
2
12/28/2013 1:23:17 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow