Exemple #1
0
 private static void RemoveDepartmentByState(ContosoUniversityEntities db)
 {
     db.Entry(new Department()
     {
         DepartmentID = 56
     }).State = EntityState.Deleted;
     db.SaveChanges();
 }
Exemple #2
0
        private static void DemoEntityEntryRemove(ContosoUniversityEntities db)
        {
            //var dept = db.Department.Find(22);
            //db.Department.Remove(dept);
            var dept = db.Department.Attach(new Department()
            {
                DepartmentID = 22
            });

            db.Entry(dept).State = EntityState.Deleted;
            db.SaveChanges();
        }