예제 #1
0
 public List <Person> GetAll()
 {
     using (var context = new PeopleDataContext(_connectionString))
     {
         return(context.People.ToList());
     }
 }
예제 #2
0
 public Person Get(int id)
 {
     using (var context = new PeopleDataContext(_connectionString))
     {
         return(context.People.FirstOrDefault(p => p.Id == id));
     }
 }
예제 #3
0
 public void Add(Person person)
 {
     using (var context = new PeopleDataContext(_connectionString))
     {
         context.People.Add(person);
         context.SaveChanges();
     }
 }
예제 #4
0
 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();
     }
 }
예제 #5
0
 public void Delete(int id)
 {
     using (var context = new PeopleDataContext(_connectionString))
     {
         context.Database.ExecuteSqlCommand(
             "DELETE FROM People WHERE Id = @id",
             new SqlParameter("@id", id));
     }
 }
예제 #6
0
 public void Update(Person person)
 {
     using (var context = new PeopleDataContext(_connectionString))
     {
         context.People.Attach(person);
         context.Entry(person).State = EntityState.Modified;
         context.SaveChanges();
     }
 }