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的更多相关文章

  1. Entity Framework 6.0 Tutorials(1):Introduction

    以下系统文章为EF6.0知识的介绍,本章是第一篇 原文地址:http://www.entityframeworktutorial.net/entityframework6/introduction.a ...

  2. 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 ...

  3. Entity Framework 6.0 Tutorials(11):Download Sample Project

    Download Sample Project: Download a sample project for Entity Framework 6 Database-First model below ...

  4. Entity Framework 6.0 Tutorials(10):Index Attribute

    Index Attribute: Entity Framework 6 provides Index attribute to create Index on a particular column ...

  5. Entity Framework 6.0 Tutorials(9):Stored Procedure Mapping

    Code First - Insert, Update, Delete Stored Procedure Mapping: Entity Framework 6 Code-First provides ...

  6. Entity Framework 6.0 Tutorials(6):Transaction support

    Transaction support: Entity Framework by default wraps Insert, Update or Delete operation in a trans ...

  7. Entity Framework 6.0 Tutorials(3):Code-based Configuration

    Code-based Configuration: Entity Framework 6 has introduced code based configuration. Now, you can c ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. python加密之hashlib

    1.强大的hashlib,提供了用于加密相关的操作,代替了md5模块和sha模块,主要提供 SHA1, SHA224, SHA256, SHA384, SHA512 ,MD5 算法 2.hmac模块实 ...

  2. niosii 改变软核之后重新编译方法

    操作系统:Win7 64 bit 开发环境:Quartus II 12.0 (64-Bit)  + Nios II 12.0 Software Build Tools for Eclipse 使用Qu ...

  3. Yii中处理前后台登录新方法

    我一开始的做法是在后台登录时设置一个isadmin的session,然后再前台登录时注销这个session,这样做只能辨别是前台登录还是后台登录,但做不到前后台一起登录,也即前台登录了后台就退出了,后 ...

  4. hadoop文件IO

    InputStreamReader 是字节流通向字符流的桥梁:它使用指定的 charset 读取字节并将其解码为字符.它使用的字符集可以由名称指定或显式给定,或者可以接受平台默认的字符集. Input ...

  5. 动态可缓存的内容管理系统(CMS)

    摘要:内容管理系统(CMS)在各大商业站点和门户站点中扮演着重要的角色,是内容有效组织和快速发布极为重要的基础平台.目前主流的内容发布系统都使用静态页面进行内容发布,在我们的实际使用过程中我们深切的感 ...

  6. Ambari client

    在研究如何修改YARN的资源池的时候,发现了Hortwork在github上面开源了一个Ambari Client: https://github.com/apache/ambari/tree/tru ...

  7. mybatis+druid+springboot 注解方式配置多个数据源

    1\数据库配置 #test数据源 spring.datasource.test.url=jdbc:mysql:///db?useUnicode= spring.datasource.test.user ...

  8. $GLOBALS超级全局变量(PHP学习)

    1.$GLOBALS是一个数组,里面有所有的全局变量 2.$GLOBALS是超级全局变量,函数内部可以通过它直接操作全局变量.(严重不推荐,因为违反了封装原则) 3.通过$GLOBALS操作全局变量, ...

  9. strtotime出现时区问题不一致的解决方法

    学习源头:https://blog.csdn.net/longjuanfengzc/article/details/80622842 https://segmentfault.com/q/101000 ...

  10. ZipArchive扩展的使用和Guzzle依赖的安装使用

    在项目开发的过程中,需要去远程下载录音文件 然后保存到自己的项目中,然后再把录音文件压缩打包,最后再下载给用户 1.Guzzle依赖的安装 guzzle官方文档:http://guzzle-cn.re ...