Once the properties were filled, the populated Contact was added to the
strongly typed Contact table via the Add method. In other words, the previous example modified object
members directly.
There is another way, which is essentially the same as the last inset example but adds an object to the
LINQ to SQL collection (the Table(of T) collection) and hands that off for submission to the database.
The following example shows how this is accomplished:
AdventureWorks db = new AdventureWorks("Integrated Security=sspi");
Contact con = new Contact
225
Part III: LINQ to SQL
{
FirstName = "Scott",
MiddleName = "L",
LastName = "Klein",
Title = "Geek",
EmailAddress = "geek@email.com",
EmailPromotion = 1,
NameStyle = 0,
PasswordHash = "",
PasswordSalt = ""
} ;
db.Contact.Add(con);
db.SubmitChanges();
textBox1.Text = "Contact created.";
The differences between this example and the previous Insert example are not that major. The results are
the same; it is just a matter of implementation.
Update
Rows can be updated by modifying the value members of the objects.
Pages:
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370