博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
EntityFramework 学习 一 Add Entity Graph using DbContext:
阅读量:5139 次
发布时间:2019-06-13

本文共 1104 字,大约阅读时间需要 3 分钟。

//Create student in disconnected modeStudent newStudent = new Student() { StudentName = "New Single Student" };            //Assign new standard to student entitynewStudent.Standard = new Standard() { StandardName = "New Standard" };            //add new course with new teacher into student.coursesnewStudent.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());}

 

转载于:https://www.cnblogs.com/lanpingwang/p/6618625.html

你可能感兴趣的文章
PAT 1055. 集体照 (25)
查看>>
python(wordcloud)实现中文词云
查看>>
JQuery AJAX请求分类示例
查看>>
Python Numpy数组保存
查看>>
同一个中断正在执行中还会重入么
查看>>
2.Struts2的Action接口和 ActionSuppor类
查看>>
使IE6、IE7、IE8支持CSS3代码方法
查看>>
codereviw得到的一些经验
查看>>
TreeSet介绍
查看>>
MVC4 下DropDownList使用方法
查看>>
tomcat war包自动化部署脚本
查看>>
502 bad gateway 错误
查看>>
day20 BBS前奏
查看>>
常见JS写法
查看>>
numpy的计算
查看>>
SQL数据库完全复制
查看>>
python 语法学习
查看>>
数据转换类型和算数运算符
查看>>
sql in 和 exist的区别
查看>>
java.lang.NoClassDefFoundError: org/apache/commons/codec/DecoderException 的解决办法
查看>>