public List <Person> GetAll() { using (var context = new PeopleDataContext(_connectionString)) { return(context.People.ToList()); } }
public Person Get(int id) { using (var context = new PeopleDataContext(_connectionString)) { return(context.People.FirstOrDefault(p => p.Id == id)); } }
public void Add(Person person) { using (var context = new PeopleDataContext(_connectionString)) { context.People.Add(person); context.SaveChanges(); } }
public void Delete(List <int> ids) { using (var context = new PeopleDataContext(_connectionString)) { var peopleToDelete = context.People.Where(p => ids.Contains(p.Id)); context.People.RemoveRange(peopleToDelete); context.SaveChanges(); } }
public void Delete(int id) { using (var context = new PeopleDataContext(_connectionString)) { context.Database.ExecuteSqlCommand( "DELETE FROM People WHERE Id = @id", new SqlParameter("@id", id)); } }
public void Update(Person person) { using (var context = new PeopleDataContext(_connectionString)) { context.People.Attach(person); context.Entry(person).State = EntityState.Modified; context.SaveChanges(); } }