Johnny
Johnny

Reputation: 1575

Generic List to EntitySet Conversion

How do I Convert a System.Collections.Generic.List<T> to a System.Data.Linq.EntitySet<T> ?

Upvotes: 14

Views: 12939

Answers (2)

Julien Hoarau
Julien Hoarau

Reputation: 49980

Don't think you can convert a List<T> to an EntitySet<T> but you can put the content of your list in the entitySet.

var list = new List<string> { "a", "b", "c" };
var entitySet = new EntitySet<string>();
entitySet.AddRange(list);

Here's a extension method for that:

public static EntitySet<T> ToEntitySet<T>(this IEnumerable<T> source) where T : class
{
    var es = new EntitySet<T>();
    es.AddRange(source);
    return es;
}

Upvotes: 34

Darin Dimitrov
Darin Dimitrov

Reputation: 1039080

var list = new List<string> 
{ 
    "element1", "element2" 
};
var entitySet = new EntitySet<string>();
entitySet.AddRange(list);

Upvotes: 11

Related Questions