예제 #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));
     }
 }
예제 #2
0
 public List <Person> GetPeople()
 {
     using (var context = new PCContext(_connectionString))
     {
         return(context.People.Include(p => p.Cars).ToList());
     }
 }
예제 #3
0
 public void AddCar(Car car)
 {
     using (var context = new PCContext(_connectionString))
     {
         context.Cars.Add(car);
         context.SaveChanges();
     }
 }
예제 #4
0
 public void AddPerson(Person person)
 {
     using (var context = new PCContext(_connectionString))
     {
         context.People.Add(person);
         context.SaveChanges();
     }
 }
예제 #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));
     }
 }