// Add a new row using "longhand" notation.
Inventory newCar = new Inventory();
newCar.Make = "Yugo";
newCar.Color = "Pink";
newCar.PetName = "Betty";
newCar.CarID = newCarID;
ctx.Inventories.InsertOnSubmit(newCar);
ctx.SubmitChanges();
Console.Write("Enter ID for Henry: ");
newCarID = int.Parse(Console.ReadLine());
// Add another row using "shorthand" object init syntax.
newCar = new Inventory { Make = "BMW", Color = "Silver",
PetName = "Henry", CarID = newCarID };
ctx.Inventories.InsertOnSubmit(newCar);
ctx.SubmitChanges();
}
Updating Existing Items
Updating an item is also very straightforward. Based on your LINQ query, extract the first item that
meets the search criteria. Once you update the object’s state, once again call SubmitChanges().
static void UpdateCar(AutoLotObjectsDataContext ctx)
{
Console.WriteLine("***** Updating color of 'Betty' *****");
Do'stlaringiz bilan baham: |