October 2010
Intermediate to advanced
1920 pages
73h 55m
English
There are two steps to adding and inserting a new record with LINQ to SQL. First, you need to use the InsertOnSubmit() method to add an entity to an existing table. Next, you call SubmitChanges() on the DataContext to execute the SQL INSERT statement against the database.
The class in Listing 20.22 illustrates how you can write a method to add a new record into the Movie database table.
Listing 20.22. Standard\App_Code\Movie.cs

The Movie class includes an Insert() method that inserts a new movie into the database. The Insert() method returns an integer that represents the identity value of the new record. As soon as ...
Read now
Unlock full access