public void SaveAll(TrainEntity[] entities) { if (entities == null) { return; } using (var db = new TrainTrainContext()) { db.Trains.AddOrUpdate(entities); db.SaveChanges(); } }
public void Remove(string trainId) { using (var db = new TrainTrainContext()) { var train = db.Trains.Include(t => t.Seats).SingleOrDefault(t => t.TrainId == trainId); if (train != null) { train.Seats.RemoveAll(t => true); RemoveSeats(db); db.Trains.Remove(train); } db.SaveChanges(); } }
public void RemoveAll() { using (var db = new TrainTrainContext()) { var trains = db.Trains.Include(t => t.Seats).ToList(); if (trains.Any()) { foreach (var trainEntity in trains) { trainEntity.Seats.RemoveAll(t => true); RemoveSeats(db); db.Trains.Remove(trainEntity); } } db.SaveChanges(); } }