示例#1
0
 public void Delete(int id)
 {
     using (var context = new PeopleDataContext(_connectionString))
     {
         context.ExecuteCommand("DELETE FROM People WHERE Id = {0}", id);
     }
 }
示例#2
0
 public Person GetById(int id)
 {
     using (var context = new PeopleDataContext(_connectionString))
     {
         return(context.Persons.FirstOrDefault(p => p.Id == id));
     }
 }
示例#3
0
 public IEnumerable <Person> GetPeople()
 {
     using (var context = new PeopleDataContext(_connectionString))
     {
         return(context.Persons.ToList());
     }
 }
示例#4
0
 public void Add(Person person)
 {
     using (var context = new PeopleDataContext(_connectionString))
     {
         context.Persons.InsertOnSubmit(person);
         context.SubmitChanges();
     }
 }
示例#5
0
 public void Update(Person person)
 {
     using (var context = new PeopleDataContext(_connectionString))
     {
         context.Persons.Attach(person);
         context.Refresh(RefreshMode.KeepCurrentValues, person);
         context.SubmitChanges();
     }
 }