public Person GetPersonById(int id) { using (var context = new PCContext(_connectionString)) { return(context.People.Include(p => p.Cars).FirstOrDefault(p => p.Id == id)); } }
public List <Person> GetPeople() { using (var context = new PCContext(_connectionString)) { return(context.People.Include(p => p.Cars).ToList()); } }
public void AddCar(Car car) { using (var context = new PCContext(_connectionString)) { context.Cars.Add(car); context.SaveChanges(); } }
public void AddPerson(Person person) { using (var context = new PCContext(_connectionString)) { context.People.Add(person); context.SaveChanges(); } }
public void DeleteCars(int id) { using (var context = new PCContext(_connectionString)) { context.Database.ExecuteSqlRaw( "DELETE FROM Cars WHERE PersonId = @id", new SqlParameter("@id", id)); } }