Exemple #1
0
        protected void Button3_Click(object sender, EventArgs e)
        {
            EFFristModelEntities db = new EFFristModelEntities();
            //var userInfoList = from u in db.UserInfo
            //                   where u.ID == 345
            //                   select u;
            //UserInfo userInfo=userInfoList.FirstOrDefault();//返回第一个元素,如果没有的话,返回null
            //if (userInfo != null)
            //{
            //   // db.UserInfo.Remove(userInfo);
            //    db.Entry<UserInfo>(userInfo).State = System.Data.EntityState.Deleted;

            //    db.SaveChanges();
            //}
            //else
            //{
            //    Response.Write("要删除的数据不存在!!");
            //}

            UserInfo userInfo = new UserInfo()
            {
                ID = 344
            };

            //db.UserInfo.Remove(userInfo);
            db.Entry <UserInfo>(userInfo).State = System.Data.EntityState.Deleted;
            db.SaveChanges();
        }
Exemple #2
0
        protected void Button4_Click(object sender, EventArgs e)
        {
            EFFristModelEntities db = new EFFristModelEntities();
            var userInfoList        = from u in db.UserInfo
                                      where u.ID == 343
                                      select u;
            var userInfo = userInfoList.FirstOrDefault();

            userInfo.UserPass = "******";
            db.Entry <UserInfo>(userInfo).State = System.Data.EntityState.Modified;
            db.SaveChanges();
        }