Generic List to EntitySet Conversion

送分小仙女□ 提交于 2019-12-23 06:57:28

问题


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


回答1:


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



回答2:


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


来源:https://stackoverflow.com/questions/2848680/generic-list-to-entityset-conversion

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!