首页 > 代码库 > EntityFramework 学习 一 Add Entity Graph using DbContext:
EntityFramework 学习 一 Add Entity Graph using DbContext:
//Create student in disconnected mode Student newStudent = new Student() { StudentName = "New Single Student" }; //Assign new standard to student entity newStudent.Standard = new Standard() { StandardName = "New Standard" }; //add new course with new teacher into student.courses newStudent.Courses.Add(new Course() { CourseName = "New Course for single student", Teacher = new Teacher() { TeacherName = "New Teacher" } }); using (var context = new SchoolDBEntities()) { context.Students.Add(newStudent); context.SaveChanges(); Console.WriteLine("New Student Entity has been added with new StudentId= " + newStudent.StudentID.ToString()); Console.WriteLine("New Standard Entity has been added with new StandardId= " + newStudent.StandardId.ToString()); Console.WriteLine("New Course Entity has been added with new CourseId= " + newStudent.Courses.ElementAt(0).CourseId.ToString()); Console.WriteLine("New Teacher Entity has been added with new TeacherId= " + newStudent.Courses.ElementAt(0).TeacherId.ToString()); }
EntityFramework 学习 一 Add Entity Graph using DbContext:
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。