I have a list of objects that I'm inserting in a database with linq-to-sql. At the moment, I'm using a foreach loop that adds each element and that looks roughly like this:
foreach (o in List<MyObjectModel)
{
using MyDataContext
{
TheLinqToSqlTableModel TheTable = new TheLinqToSqlTableModel();
TheTable.Fieldname = o.Fieldname;
.... repeat for each field
MyDataContext.TheTablename.InsertOnSubmit(TheTable);
MyDataContext.SubmitChanges();
}
}
Is there a better way to insert a list of objects in a DB using linq-to-sql?
Thanks for your suggestions.