KoffeeKoder


  • Recently, I had a requirement to convert an IEnumerable to EntitySet. Off course, you can create a helper class with a separate convert method but I think this scenario qualifies for Extension Methods. Here is the ToEntitySet code which converts an IEnumerableto EntitySet

      // convert IEnumerable to an EntitySet
            public static EntitySet<T> ToEntitySet<T>(this IEnumerable<T> e) where T : class
            {
                if (e == null || e.Count() == 0)
                    throw new ArgumentException("List null or does not contains any elements");

                EntitySet<T> set = new EntitySet<T>();
                set.AddRange(e);
                return set;            
            }