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 ...
随机推荐
- Anaconda 使用conda常用命令
1.首先在所在系统中安装Anaconda.可以打开命令行输入conda -V检验是否安装以及当前conda的版本. 2.conda常用的命令. 1)conda list 查看安装了哪些包. 2)con ...
- TOP K问题的若干实现
问题描述:在长度为n的序列中,找出其最大的K个数 1.冒泡排序 每冒泡一次,可将最大的数放到序列尾部,冒泡K次即可. 时间复杂度:O(K*n) 空间复杂度:O(1) 2.扫描数组,将最大的N个数存在缓 ...
- 18.Selenium+Python案例 -- 豆瓣
一.具体代码实现: from selenium import webdriver driver = webdriver.Firefox() driver.get('https://www.douban ...
- Linux:常用命令讲解(系统、防火墙、提权与文件传输)
一.系统用户操作指令 一般在 Linux 系统中有多个账号,但一般不推荐使用 root 账号,因为 root 账号的权限太大,如果账号泄露会有安全隐患: 一般配置软件时也不要在 root 账号下进行: ...
- 微信小程序之wx.requestPayment 发起微信支付
wx.requestPayment 发起微信支付 timeStamp 时间戳 nonceStr 随机字符串 package 统一下单接口返回的 prepay_id 参数值 signType 签名算法 ...
- Py修行路 python基础(一)初识
编译:把铭文代码执行前,先转成二进制,再执行,这个过程就叫编译. 编译型c,c++go特点:运行效率高依赖编译平台,linux 操作系统 跟CPU交互的接口,与windows不是完全一样不能跨平台,开 ...
- 使用 Ansible 管理 MySQL 复制
Ansible 是一个新兴的 IT 自动化工具.本文将介绍如何通过 Ansible 配置及管理 MySQL 主.从复制环境,实现部署过程自动化,体验 Ansible 简单快速带来的快感. 简介: An ...
- python's twenty-fifth day for me 模块
模块: py文件就是模块. python之所以好用,因为模块多. 内置模块:python安装的时候自带的. 扩展模块:别人写好的,需要安装后可直接使用. 自定义模块:自己写的模块. 序列化模块: 能存 ...
- ngnix 403 forbidden的解决办法
1.在网站根目录下新建文件index.html.index.php. 2.主要是修改nginx的配置文件nginx.conf权限为755即可访问.
- 让你的javascript代码高大上
1,创造简短的写法 你可以这么写: var slice = Array.prototype.slice; slice.call(arguments); //转化成数组 也可以这么写:(ie9+) va ...