Home
About Me
Categories
C#
(11)
ASP.NET
(34)
JavaScript
(6)
CSS
(1)
XSLT
(1)
Unit Testing
(22)
Architecture
(23)
Ajax
(8)
LINQ to SQL
(2)
ASP.NET MVC
(5)
Life
(18)
Book Reviews
(2)
WPF
(13)
Projects
(2)
Convert IEnumerable
to EntitySet
Using Extension Methods
published on 5/29/2008 11:14:58 AM
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;
}
Name:
Name:
Email:
Comment/Feedback: