コード例 #1
0
        public static void UpdateOnlyDepartmentNoTracking()
        {
            List <Subject> subjectsWithDepartment = context.Subjects.Include(s => s.Department).ToList();

            using StudentsContext newcontext = new StudentsContext();
            Subject s = subjectsWithDepartment[0];

            s.Department.Name = "Department Update No Tracking";

            newcontext.Attach(s);
            newcontext.Entry(s.Department).State = EntityState.Modified;
            newcontext.SaveChanges();
        }