Say I have:
using (SomeDataContext db = new SomeDataContext())
{
foreach(Item i in Items)
{
DbItem d = new DbItem;
d.value = i.value;
//.... etc ...
db.InsertOnSubmit(d);
}
db.SubmitChanges();
}
Is it possible and/or better (worse?) to do:
using (SomeDataContext db = new SomeDataContext())
{
IEnumerable<DbItem> dbItems = //???? possible?
foreach(Item i in Items)
{
DbItem d = new DbItem;
d.value = i.value;
//.... etc ...
dbItems.Add(d); // ???? again, somehow possible?
}
db.InsertAllOnSubmit(dbItems);
db.SubmitChanges();
}
Well you could use List<T>
:
using (SomeDataContext db = new SomeDataContext())
{
List<DbItem> dbItems = new List<DbItem>();
foreach(Item i in Items)
{
DbItem d = new DbItem;
d.value = i.value;
//.... etc ...
dbItems.Add(d);
}
db.InsertAllOnSubmit(dbItems);
db.SubmitChanges();
}
Whether that will be any more efficient or not, I don't know.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With