Пример #1
0
 public void DeletePerson(int id)
 {
     using (PeopleDbDataContext context = new PeopleDbDataContext(_connectionString))
     {
         context.ExecuteCommand("DELETE FROM People WHERE Id = {0}", id);
     }
 }
Пример #2
0
 public Person GetById(int id)
 {
     using (PeopleDbDataContext context = new PeopleDbDataContext(_connectionString))
     {
         return(context.Persons.First(p => p.Id == id));
     }
 }
Пример #3
0
 public IEnumerable <Person> GetPeople()
 {
     using (PeopleDbDataContext context = new PeopleDbDataContext(_connectionString))
     {
         return(context.Persons.ToList());
     }
 }
Пример #4
0
 public void AddPerson(Person person)
 {
     using (PeopleDbDataContext context = new PeopleDbDataContext(_connectionString))
     {
         context.Persons.InsertOnSubmit(person);
         context.SubmitChanges();
     }
 }
Пример #5
0
 public void AddCar(Car car)
 {
     using (var context = new PeopleDbDataContext(_connectionString))
     {
         context.Cars.InsertOnSubmit(car);
         context.SubmitChanges();
     }
 }
Пример #6
0
 public void UpdatePerson(Person person)
 {
     using (PeopleDbDataContext context = new PeopleDbDataContext(_connectionString))
     {
         context.Persons.Attach(person);
         context.Refresh(RefreshMode.KeepCurrentValues, person);
         context.SubmitChanges();
     }
 }
Пример #7
0
 public IEnumerable <Car> GetCars(int personId)
 {
     using (var context = new PeopleDbDataContext(_connectionString))
     {
         var loadOptions = new DataLoadOptions();
         loadOptions.LoadWith <Car>(c => c.Person);
         context.LoadOptions = loadOptions;
         return(context.Cars.Where(c => c.PersonId == personId).ToList());
     }
 }
Пример #8
0
 public IEnumerable <Person> GetAll()
 {
     using (var context = new PeopleDbDataContext(_connectionString))
     {
         var loadOptions = new DataLoadOptions();
         loadOptions.LoadWith <Person>(p => p.Cars);
         context.LoadOptions = loadOptions;
         return(context.Persons.ToList());
     }
 }