2.1 Check if ID exists //2.2 perform delete models.student stu = new Models.student () {id = id}; Db. Students.attach (Stu); Db. Students.remove (Stu); Dbentityentry<models.student> entry = db. Entry<models.student> (Stu); Entry. state = System.Data.EntityState.Deleted; int res = db. SaveChanges (); if (res>0)//delete succeeded Response.Write ("<script>alert (' Delete succeeded ~~! '); window.location= '/stu/index ';</script> ");
3.1.3.2 queries the class data and turns it into a drop-down box option set list<selectlistitem> listclass = db. Classes.where (C=>c.cisdel==false). ToList ()//Query the data first and turn it into the Entity list collection . Select (c=> new SelectListItem () {Text = c.cname, Value = C.cid. ToString (), Selected = (stu. CId = = c.cid)}). ToList ();//Convert entity collection to SelectListItem collection
Various removal methods for EF