What is the best way to insert new child records: to use Add()
or InsertOnSubmit()
?
Is there any difference between those to approaches ?
InsertOnSubmit()
example:
using (DataContext db = new DataContext())
{
Parent p = db.Parents.Where(q => q.ID == SomeID).SingleOrDefault();
Child c = new Child();
c.ForeignKeyID = p.ID;
db.InsertOnSubmit(c);
db.SubmitChanges();
}
Add()
example:
using (DataContext db = new DataContext())
{
Parent p = db.Parents.Where(q => q.ID == SomeID).SingleOrDefault();
Child c = new Child();
p.Add(c);
db.SubmitChanges();
}
Parent.Add
defined?