Entity Framework 6.0 Tutorials(7):DbSet.AddRange & DbSet.RemoveRange
DbSet.AddRange & DbSet.RemoveRange:
DbSet in EF 6 has introduced new methods AddRange & RemoveRange. DbSet.AddRange adds collection(IEnumerable) of entities to the DbContext, so you don't have to add each entity individually.
IList<Student> newStudents = new List<Student>();
newStudents.Add(new Student() { StudentName = "Student1 by addrange" });
newStudents.Add(new Student() { StudentName = "Student2 by addrange" });
newStudents.Add(new Student() { StudentName = "Student3 by addrange" }); using (var context = new SchoolDBEntities())
{
context.Students.AddRange(newStudents);
context.SaveChanges();
}
Similarly, DbSet.RemoveRange is used to remove collection of entities from DbSet.
IList<Student> existingStudents = ….. using (var context = new SchoolDBEntities())
{
context.Students.RemoveRange(existingStudents);
context.SaveChanges();
}
Download sample project for DbSet.AddRange demo.
Entity Framework 6.0 Tutorials(7):DbSet.AddRange & DbSet.RemoveRange的更多相关文章
- Entity Framework 6.0 Tutorials(1):Introduction
以下系统文章为EF6.0知识的介绍,本章是第一篇 原文地址:http://www.entityframeworktutorial.net/entityframework6/introduction.a ...
- Entity Framework 6.0 Tutorials(4):Database Command Logging
Database Command Logging: In this section, you will learn how to log commands & queries sent to ...
- Entity Framework 6.0 Tutorials(11):Download Sample Project
Download Sample Project: Download a sample project for Entity Framework 6 Database-First model below ...
- Entity Framework 6.0 Tutorials(10):Index Attribute
Index Attribute: Entity Framework 6 provides Index attribute to create Index on a particular column ...
- Entity Framework 6.0 Tutorials(9):Stored Procedure Mapping
Code First - Insert, Update, Delete Stored Procedure Mapping: Entity Framework 6 Code-First provides ...
- Entity Framework 6.0 Tutorials(6):Transaction support
Transaction support: Entity Framework by default wraps Insert, Update or Delete operation in a trans ...
- Entity Framework 6.0 Tutorials(3):Code-based Configuration
Code-based Configuration: Entity Framework 6 has introduced code based configuration. Now, you can c ...
- Entity Framework 6.0 Tutorials(2):Async query and Save
Async query and Save: You can take advantage of asynchronous execution of .Net 4.5 with Entity Frame ...
- Entity Framework 6.0 Tutorials(8):Custom Code-First Conventions
Custom Code-First Conventions: Code-First has a set of default behaviors for the models that are ref ...
随机推荐
- 关于modelsim添加库的说明
声明:以下纯属个人习惯. 1.工程建好后添加一个编译好的库的方法是:file->new->library选择a map to an existing library.然后将这个库在你这工程 ...
- LA3890 Most Distant Point from the Sea
题意 PDF 分析 可以二分答案,检验就用半平面交,如果平面非空则合法. 时间复杂度\(O(T n \log^2 n)\) 代码 #include<iostream> #include&l ...
- 51nod 1965 奇怪的式子 —— min_25筛
题目:http://www.51nod.com/Challenge/Problem.html#!#problemId=1965 推式子就同这里:https://www.cnblogs.com/yoyo ...
- 七、Jmeter + ant + jenkins轻量级接口自动化测试
七.Jmeter + ant + jenkins轻量级接口自动化测试 杀猪不用牛刀,工具没有牛逼高大尚之分,每个工具都有存在的理由:关键是看会不会用,怎么用,有没有用在合适的地方. 需要安装的工具: ...
- 转载:解决eclipse导出javadoc时的“错误: 编码GBK的不可映射字符”问题
转自:http://blog.csdn.net/psy1100/article/details/51179342 今天要将自己的API接口和MODEL导出来一份java doc参考文档, 但是在导出的 ...
- Git&Repo 命令大全 ***
首先理解几个基本概念: origin:默认远程版本库: master:默认开发分支: 查看本地更新状态: git status jiangzhaowei@ubuntu$ git status # On ...
- javaMail邮件接收解析内容及附件 及删除邮件
参考自: http://blog.csdn.net/xyang81/article/details/7675160 package com.szy.project.utils; import jav ...
- HDOJ5876(补图的最短路)
Sparse Graph Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)To ...
- PTA 是否同一棵二叉搜索树(25 分)
是否同一棵二叉搜索树(25 分) 给定一个插入序列就可以唯一确定一棵二叉搜索树.然而,一棵给定的二叉搜索树却可以由多种不同的插入序列得到.例如分别按照序列{2, 1, 3}和{2, 3, 1}插入初始 ...
- Java-Runoob:Java 对象和类
ylbtech-Java-Runoob:Java 对象和类 1.返回顶部 1. Java 对象和类 Java作为一种面向对象语言.支持以下基本概念: 多态 继承 封装 抽象 类 对象 实例 方法 重载 ...