示例#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();
     }
 }