如何将System.Collections.Generic.List<T>转换为System.Data.Linq.EntitySet<T>

最佳答案

不要以为您可以将List<T>转换为EntitySet<T>,但是可以将列表的内容放入entitySet中。

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

这是一个扩展方法:
public static EntitySet<T> ToEntitySet<T>(this IEnumerable<T> source) where T : class
{
    var es = new EntitySet<T>();
    es.AddRange(source);
    return es;
}

07-25 21:29