开发者

linq to List problem in C#

开发者 https://www.devze.com 2023-01-21 09:01 出处:网络
I have class Zones with properties and i want add data which i read with linq to this properties. example

I have class Zones with properties and i want add data which i read with linq to this properties.

example

List<Zones> z = new 开发者_运维技巧List<Zones>
z.add(new Zones(...));

var allZones = from s in db.Zones select s;

How can i add allZones to z generic List?


You can do it in a number of ways:

z.AddRange(allZones);    // if there are other elements in z
z = allZones.ToList();   // if there are no other elements in z (creates a new list)


allZones.ForEach(x => z.Add(x));

or

z.AddRange(allZones.ToList());


If allZones is IEnumerable<Zones> the you can use

z.AddRange(allZones)


z.AddRange(allZones.ToList())


var z = db.Zones.ToList();

Then add any new zones to the list.

or

z.AddRange(db.Zones);


z=db.select(X=>X.Zones).ToList()

0

精彩评论

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