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