Inserting New Items
Adding new items to a relational database is as simple as creating a new instance of a given entity
class, adding into the Table type maintained by the DataContext and calling SubmitChanges().
The following InsertNewCars() method adds two new listings to the Inventory table. The first
approach directly sets each field of the Inventory entity class, while the second approach makes
use of the more compact object initialization syntax:
static void InsertNewCars(AutoLotObjectsDataContext ctx)
{
Console.WriteLine("***** Adding 2 Cars *****");
int newCarID = 0;
Console.Write("Enter ID for Betty: ");
newCarID = int.Parse(Console.ReadLine());
Do'stlaringiz bilan baham: |