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:的更多相关文章
- EntityFramework 学习 一 Update Entity Graph using DbContext:
使用主键属性 每个实体必须有主键 默认值的id属性值必须为0 在context2中,它不知道实体的状态, 只能通过实体的主键来判断实体的状态 如果主键为0,则是新的对象,不为0 就是修改 Standa ...
- Entity Framework Tutorial Basics(26):Add Entity Graph
Add Entity Graph using DbContext: Adding entity graph with all new entities is a simple task. We can ...
- EntityFramework 学习 一 Add New Entity using DBContext in Disconnected Scenario
using System; using System.Collections.Generic; public partial class Student { public Student() { th ...
- EntityFramework 学习 一 Delete Entity using DBContext in Disconnected Scenario
Student studentToDelete; . Get student from DB using (var ctx = new SchoolDBEntities()) { studentToD ...
- EntityFramework 学习 一 Validate Entity
可以为实体实现自定义验证,重写DBContext中的个ValidateEntity方法 protected override System.Data.Entity.Validation.DbEntit ...
- EntityFramework 学习 一 Colored Entity in Entity Framework 5.0
You can change the color of an entity in the designer so that it would be easy to see related groups ...
- Entity Framework Tutorial Basics(27):Update Entity Graph
Update Entity Graph using DbContext: Updating an entity graph in disconnected scenario is a complex ...
- EntityFramework 学习 一 Disconnected Entities
如何把断开的实体添加到新的context上下文中 1.首先,我们需要把实体附加到新的context上下文实例中. 2.其次,手动的给实体设置适当的实体状态,因为新的context上下文不知道断开的实体 ...
- Entityframework:“System.Data.Entity.Internal.AppConfig”的类型初始值设定项引发异常。
<configSections> <!-- For more information on Entity Framework configuration, visit http:// ...
随机推荐
- spring利用ApplicationListener自启动
近期在用mina获取server的数据,但没有和spring进行集成,就利用ApplicationListener实现了自启动 package com.gamesvr.minaenpo; import ...
- Java基础IO流
流 流的本质是数据传输,根据数据传输特性将流抽象为各种类,方便更直观的进行数据操作.IO流最终要以对象来体现,对象都存在IO包中. IO流的分类 根据处理数据类型的不同分为:字符流和字节流 根据数据流 ...
- 【数据挖掘】分类之Naïve Bayes(转载)
[数据挖掘]分类之Naïve Bayes 1.算法简介 朴素贝叶斯(Naive Bayes)是监督学习的一种常用算法,易于实现,没有迭代,并有坚实的数学理论(即贝叶斯定理)作为支撑. 本文以拼写检查作 ...
- (1)安装kvm
我的环境是redhat虚拟机,版本信息如下: [root@localhost ~]# cat /etc/issue Red Hat Enterprise Linux Server release 6. ...
- 苹果mac shell 终端 命令行快捷键——行首行尾
ctrl+a //移到行首 ctrl+e //移到行尾 http://blog.csdn.net/hherima/article/details/47083739
- 推荐一个android 日期时间选择器(转)
最近接触了日期选择的功能,那么肯定得需要一个日期选择控件,Android 系统有自带的 DatePicker 控件,但是不说这个控件有多 难看吧,现在 Android 手机版本那么多,用户弹出来的控件 ...
- [原]Nginx+Lua服务端合并静态文件
http://homeway.me 0x01.About 源代码已经上传到github:https://github.com/grasses/nginx-lua-static-merger nginx ...
- 移动端实用的meta标签
直接上代码,代码自有颜如玉 代码自有黄金屋啊 <meta http-equiv="Content-Type" content="text/html; charset ...
- 动态创建Lambda表达式实现高级查询
需求简介 最近这几天做的东西总算是回归咱的老本行了,给投资管理项目做一个台账的东西,就是类似我们的报表.其 中有一个功能是一个高级查询的需求,在查询条件方面大概有7.8个查询条件.需求就是如果一个条件 ...
- python 正則表達式推断邮箱格式是否正确
import re def validateEmail(email): if len(email) > 7: if re.match("^.+\\@(\\[?) ...