开发者

Generic List to EntitySet Conversion

开发者 https://www.devze.com 2022-12-30 19:02 出处:网络
How do I Convert a Sys开发者_如何学JAVAtem.Collections.Generic.List<T> to a System.Data.Linq.EntitySet<T> ?Don\'t think you can convert a List<T> to an EntitySet<T> but you can

How do I Convert a Sys开发者_如何学JAVAtem.Collections.Generic.List<T> to a System.Data.Linq.EntitySet<T> ?


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;
}


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

精彩评论

暂无评论...
验证码 换一张
取 消