Exemplo n.º 1
0
 public Person GetById(int id)
 {
     using (var db = new FamilyContext())
     {
         return db.People.Find(id);
     }
 }
Exemplo n.º 2
0
 public int Add(Person p)
 {
     using (var db = new FamilyContext()) {
     db.People.Add(p);
     db.SaveChanges();
     return p.Id;
       }
 }
Exemplo n.º 3
0
        public List<Models.Person> GetAllPeople()
        {
            using (var db = new FamilyContext()) {
            var q = from p in db.People
                select p;

            return q.ToList();
              }
        }
Exemplo n.º 4
0
 public void Delete(int id)
 {
     using (var db = new FamilyContext()) {
     Person p = new Person();
     p.Id = id;
     db.People.Attach(p);
     db.Entry(p).State = System.Data.EntityState.Deleted;
     int n = db.SaveChanges();
     Debug.Print("delete={0} rows", n);
       }
 }
Exemplo n.º 5
0
        public void Update(Person p)
        {
            using (var db = new FamilyContext()) {
            var personFromDb = db.People.Find(p.Id); // state->unchanged

            // if (!p.Equals(personFromDb)) {
            personFromDb.Name = p.Name;
            personFromDb.Gender = p.Gender;
            personFromDb.BirthYear = p.BirthYear;
            // }

            int n = db.SaveChanges();
            Debug.Print("update={0} rows", n);
              }
        }
Exemplo n.º 6
0
        public void Update(Person p)
        {
            using (var db = new FamilyContext())
            {
                var personFromDb = db.People.Find(p.Id);

                //if(!p.Equals(personFromDb))
               // {
                    //db.People.Attach(p);
                    //db.Entry(p).State = System.Data.EntityState.Modified;
                    personFromDb.Name = p.Name;
                    personFromDb.Gender = p.Gender;
                    personFromDb.BirthYear = p.BirthYear;
                //}

                //db.People.Attach(p);
                //db.Entry(p).State = System.Data.EntityState.Modified;
                int n = db.SaveChanges();
                Debug.Print("update={0} rows", n);
            }
        }