public void DeleteCarsForPerson(int personId) { using var context = new PeopleCarsDbContext(_connectionString); context.Database.ExecuteSqlInterpolated($"DELETE FROM Cars WHERE PersonId = {personId}"); }
public void AddPerson(Person person) { using var context = new PeopleCarsDbContext(_connectionString); context.People.Add(person); context.SaveChanges(); }
public void AddCar(Car car) { using var context = new PeopleCarsDbContext(_connectionString); context.Cars.Add(car); context.SaveChanges(); }
public List <Car> GetCarsForPerson(int id) { using var context = new PeopleCarsDbContext(_connectionString); return(context.Cars.Where(c => c.PersonId == id).ToList()); }
public Person GetById(int id) { using var context = new PeopleCarsDbContext(_connectionString); return(context.People.FirstOrDefault(p => p.Id == id)); }
public List <Person> GetAllPeople() { using var context = new PeopleCarsDbContext(_connectionString); return(context.People.Include(p => p.Cars).ToList()); }