Exemplo n.º 1
0
 public void DeletePerson(int id)
 {
     using (PeopleDbDataContext context = new PeopleDbDataContext(_connectionString))
     {
         context.ExecuteCommand("DELETE FROM People WHERE Id = {0}", id);
     }
 }
Exemplo n.º 2
0
 public Person GetById(int id)
 {
     using (PeopleDbDataContext context = new PeopleDbDataContext(_connectionString))
     {
         return(context.Persons.First(p => p.Id == id));
     }
 }
Exemplo n.º 3
0
 public IEnumerable <Person> GetPeople()
 {
     using (PeopleDbDataContext context = new PeopleDbDataContext(_connectionString))
     {
         return(context.Persons.ToList());
     }
 }
Exemplo n.º 4
0
 public void AddPerson(Person person)
 {
     using (PeopleDbDataContext context = new PeopleDbDataContext(_connectionString))
     {
         context.Persons.InsertOnSubmit(person);
         context.SubmitChanges();
     }
 }
Exemplo n.º 5
0
 public void AddCar(Car car)
 {
     using (var context = new PeopleDbDataContext(_connectionString))
     {
         context.Cars.InsertOnSubmit(car);
         context.SubmitChanges();
     }
 }
Exemplo n.º 6
0
 public void UpdatePerson(Person person)
 {
     using (PeopleDbDataContext context = new PeopleDbDataContext(_connectionString))
     {
         context.Persons.Attach(person);
         context.Refresh(RefreshMode.KeepCurrentValues, person);
         context.SubmitChanges();
     }
 }
Exemplo n.º 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());
     }
 }
Exemplo n.º 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());
     }
 }