Various removal methods for EF

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.