views:

67

answers:

6

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?

+2  A: 

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)
Dave
+1  A: 
allZones.ForEach(x => z.Add(x));

or

z.AddRange(allZones.ToList());
Jamiec
+1  A: 

If allZones is IEnumerable<Zones> the you can use

z.AddRange(allZones)
Ivan Gerken
+1  A: 
z.AddRange(allZones.ToList())
tchrikch
+1  A: 
var z = db.Zones.ToList();

Then add any new zones to the list.

or

z.AddRange(db.Zones);
Hightechrider
+1  A: 

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

Pramodh