gpt4 book ai didi

c# - 通用列表到 EntitySet 的转换

转载 作者:可可西里 更新时间:2023-11-01 07:49:36 25 4
gpt4 key购买 nike

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

最佳答案

不要认为你可以转换 List<T>EntitySet<T>但您可以将列表的内容放入实体集中。

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

关于c# - 通用列表到 EntitySet 的转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2848680/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com