예제 #1
0
        public void AddDepartment()
        {
            using (EFCoreContext db = new EFCoreContext())
            {
                Department department = new Department();
                department.Name            = "Secuirty";
                db.Entry(department).State = EntityState.Added;

                department      = new Department();
                department.Name = "HR";
                db.Add(department);

                db.SaveChanges();

                Console.WriteLine("Department {0} ({1}) is added ", department.Name, department.DepartmentID);
            }
        }
예제 #2
0
        public void AddStatusExample()
        {
            using (EFCoreContext db = new EFCoreContext())
            {
                Department department = new Department();
                department.Name = "Production";
                db.Add(department);
                Console.WriteLine("Status Before SaveChanges " + db.Entry(department).State.ToString());

                db.SaveChanges();

                Console.WriteLine("Status After SaveChanges  " + db.Entry(department).State.ToString());
            }

            Console.WriteLine("Press any key to continue ");
            Console.ReadKey();
        }
예제 #3
0
        public void CheckStatus()
        {
            Console.WriteLine("Checking Status");



            using (EFCoreContext db = new EFCoreContext())
            {
                Department department = db.Departments.Where(f => f.Name == "HR").FirstOrDefault();
                db.Entry(department).State.ToString();
                Console.WriteLine("Status " + db.Entry(department).State.ToString());

                department = new Department();
                db.Entry(department).State.ToString();
                Console.WriteLine("Status " + db.Entry(department).State.ToString());

                db.Add(department);
                db.Entry(department).State.ToString();
                Console.WriteLine("Status " + db.Entry(department).State.ToString());
            }

            Console.WriteLine("Press any key to continue ");
            Console.ReadKey();
        }