Why is there no .AddRange() method for System.Data.Entity.IDbSet<T>? RRS feed

  • Question

  • User-1851576699 posted

    The concrete implementation of a System.Data.Entity.DbSet<TEntity> has the .AddRange() method so it would seem logical to enforce this functionality through the interface itself versus adding it on after the fact. Why is the .AddRange() method not enforced through a System.Data.Entity.IDbSet<T> inteface?

    It looks the .AddRange() method was just recently added to System.Data.Entity.DbSet<TEntity> as of Entity Framework version 6.


    It just boggles my mind why it isn't available through an IDbSet<T> type.

    Thursday, April 3, 2014 11:05 PM

All replies

  • User-1941247845 posted

    May be this will be of some help for you !!


    Friday, April 4, 2014 1:38 AM
  • User697462465 posted

    Hi TheNutCracker,

    The AddRage method is declare in DbSet class, not in IDbSet interface, so if you want to use it, you need to add the DbSet reference.

    The following links is the DbSet and IDbSet documentation:



    Hope it helps.

    Best Regards,
    Terry Guo

    Thursday, April 10, 2014 4:33 AM
  • User-1851576699 posted


    I realize there is no .AddRange() method in an IDbSet. That was part of my question. Why would there not be an .AddRange() method for an object that manipulates a DbSet? It's a little counter-intuitive.

    Thursday, April 10, 2014 11:29 AM
  • User-641466327 posted

    I had the same epiphany, I agree there is no reason except for not breaking code that already implements IDbSet - for whatever reason. In the meantime I solved it with extension methods - not pretty and hopefully compatible with some future IDbSet that implements it:

        public static class R2VDbContextExtensionMethods
            public static IEnumerable<TEntity> AddRange<TEntity>(this IDbSet<TEntity> dbset, IEnumerable<TEntity> entitiesToAdd) where TEntity : class
                return ((DbSet<TEntity>) dbset).AddRange(entitiesToAdd);

            public static IEnumerable<TEntity> RemoveRange<TEntity>(this IDbSet<TEntity> dbset, IEnumerable<TEntity> entitiesToDelete) where TEntity : class
                return ((DbSet<TEntity>) dbset).RemoveRange(entitiesToDelete);

    Yeah, half a year later


    Still working on Windows 7 and happy with it.

    Saturday, November 15, 2014 6:33 PM
  • User-1134857695 posted

    Thanks!!! It's working wonderfully!!

    Friday, May 6, 2016 8:03 PM