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. is is not == !=之间的区别

    简单来说,python中的is与is not运算符可判断两个对象是否为同一对象.若为同一个对象,则对象1 is 对象2为True .反正,若非同一个对象,则对象1 is not 对象2为True 要理 ...

  2. python RabbitMQ队列使用

    python RabbitMQ队列使用 关于python的queue介绍 关于python的队列,内置的有两种,一种是线程queue,另一种是进程queue,但是这两种queue都是只能在同一个进程下 ...

  3. git自用笔记

    同步远程库:git clone xxx.git [filename] git ls-files: 查看已经添加进暂存区的文件. 在commit前修改一个文件后(假设名为:xxx.file),想撤销时, ...

  4. next.js 简单使用

    1. 介绍 一个react.js 服务器端渲染开源项目(不只是服务器端渲染,直接也可以生成纯静态站点) 类似的解决方案有好多,比如react.js 自身的服务器渲染方案(但是使用起来就是比较怪异) g ...

  5. ncdu 查找linux下最占空间的文件(交互式查询)

    安装 wget -c https://dev.yorhel.nl/download/ncdu-1.11.tar.gz tar xzvf ncdu-1.11.tar.gz cd ncdu-1.11 ./ ...

  6. 实现对sqlite数据库增删改查

    package com.example.db.dao;import java.util.ArrayList;import java.util.List;import android.content.C ...

  7. 新机器连接老机器遇到的ERROR

    Ansible无法连接老旧机器 报错内容: [root@BI ansible]# ansible -i /etc/ansible/hosts GameServer -m ping 10.10.113. ...

  8. TCP协议中的序列号

    TCP 协议工作在OSI的传输层,是一种可靠的面向连接的数据流协议,TCP之所以可靠,是因为它保证了传送数据包的顺序.顺序是用一个序列号来保证的.响应包内也包括一个序列号,表示接收方准备好这个序列号的 ...

  9. JS,JQUERY 常用笔记

    JSON.parse() 转成数组对象 JSON.stringify() 转成JSON字符串

  10. MVC原理图解

    注解: 视图中通过Action方法向控制器请求数据 控制器通过view()方法向视图呈现数据