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