开发者

Generic List to EntitySet Conversion

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜