private static void PrintAllInventory() { //Select all items from inventory table of autolot and print using custom ToString() using (AutoLotEntities context = new AutoLotEntities()) { foreach(Car c in context.Cars) { Console.WriteLine(c); } } }
private static void RemoveRecord() { using (AutoLotEntities context = new AutoLotEntities()) { //Define a key for entity we are looking for... EntityKey key = new EntityKey("AutoLotEntities.Cars", "CarID", 2222); //see if we have key, and delete if we do Car carToDelete = (Car)context.GetObjectByKey(key); if(carToDelete != null) { context.DeleteObject(carToDelete); context.SaveChanges(); } } }
private static void AddNewRecord() { using (AutoLotEntities context = new AutoLotEntities()) { try { context.Cars.AddObject(new Car() { CarID = 2222, Make = "BMW", Color = "Silver"}); context.Cars.AddObject(new Car() { CarID = 2222, Make = "Mercedes", Color = "Yellow" }); context.SaveChanges(); } catch (Exception ex) { Console.WriteLine(ex.InnerException.Message); } } }