Beispiel #1
0
 public void deleteMember(long id)
 {
     // https://visualstudiomagazine.com/blogs/tool-tracker/2015/12/entity-framework-database-deletes.aspx
     using (var db = new MembersListEntities())
     {
         member m = db.members.First(i => i.Id == id);
         db.members.Attach(m);
         db.members.Remove(m);
         db.SaveChanges();
     }
 }
Beispiel #2
0
        public void addToDatabase(string fname, string lname, string sDate, string eDate)
        {
            using (var db = new MembersListEntities())
            {
                member newMember = new member
                {
                    // ID of every new object is one more than the ID of the last object in the table
                    Id                  = generateID(),
                    firstName           = fname,
                    lastName            = lname,
                    membershipStartDate = sDate,
                    membershipEndDate   = eDate
                };

                db.members.Add(newMember);
                db.SaveChanges();
                db.Dispose(); // I believe the "using" statement renders this redundant but hey, YouTube said so
            }
        }