Method Name

Return Type

         Description

Add

Added entity type

Adds the given entity to the context the Added state. When the changes are being saved, the entities in the Added states are inserted into the database. After the changes are saved, the object state changes to Unchanged.

Example: 
dbcontext.Students.Add(studentEntity)

AsNoTracking<Entity>

DBQuery<Entity>

Returns a new query where the entities returned will not
be cached in the DbContext. (Inherited from DbQuery.)

Entities
returned as AsNoTracking, will not be tracked by DBContext. This will be
significant performance boost for read only entities.
 

Example: 
var
studentList =
dbcontext.Students.AsNoTracking<Student>().ToList<Student>();

Attach(Entity)

Entity which was passed as parameter

Attaches the given entity to the context in the Unchanged
state

Example: 
dbcontext.Students.Attach(studentEntity);

Create

Entity

Creates a new instance of an entity for the type of this
set. This instance is not added or attached to the set. The instance returned
will be a proxy if the underlying context is configured to create proxies and
the entity type meets the requirements for creating a proxy.

Example: 
var
newStudentEntity = dbcontext.Students.Create();

Find(int)

Entity type

Uses the primary key value to attempt to find an entity
tracked by the context. If the entity is not in the context then a query will
be executed and evaluated against the data in the data source, and null is
returned if the entity is not found in the context or in the data source.
Note that the Find also returns entities that have been added to the context
but have not yet been saved to the database.

Example: 
Student
studEntity = dbcontext.Students.Find(1);

Include

DBQuery

Returns the included non generic LINQ to Entities query
against a DbContext. (Inherited from DbQuery)

Example:
var
studentList =
dbcontext.Students.Include("StudentAddress").ToList<Student>();
var
studentList = dbcontext.Students.Include(s =>
s.StudentAddress).ToList<Student>();

Remove

Removed entity

Marks the given entity as Deleted. When the changes are
saved, the entity is deleted from the database. The entity must exist in the
context in some other state before this method is called.

Example:
dbcontext.Students.Remove(studentEntity);

SqlQuery

DBSqlQuery

Creates a raw SQL query that will return entities in this
set. By default, the entities returned are tracked by the context; this can
be changed by calling AsNoTracking on theDbSqlQuery<TEntity> returned
from this method.

Example:
var
studentEntity = dbcontext.Students.SqlQuery("select * from student where
studentid = 1").FirstOrDefault<Student>();

DBSet Class(EF基础系列11)的更多相关文章

  1. 【Basics of Entity Framework】【EF基础系列1】

    EF自己包括看视频,看MSDN零零散散的学了一点皮毛,这次打算系统学习一下EF.我将会使用VS2012来学习这个EF基础系列. 现在看看EF的历史吧: EF版本 相关版本特性介绍 EF3.5 基于数据 ...

  2. 1.翻译:EF基础系列--什么是Entity Framework?

    大家好,好久不见,EF系列之前落下了,还是打算重新整理一下. 先说说目前的打算:先简单了解一下EF基础系列-->然后就是EF 6 Code-First系列-->接着就是EF 6 DB-Fi ...

  3. 10.翻译:EF基础系列---EF中的持久性

    原文链接:http://www.entityframeworktutorial.net/EntityFramework4.3/persistence-in-entity-framework.aspx ...

  4. 6.翻译:EF基础系列---什么是EF中的实体?

    原文地址:http://www.entityframeworktutorial.net/basics/what-is-entity-in-entityframework.aspx EF中的实体就是继承 ...

  5. 8.翻译:EF基础系列----EF中实体的状态

    原文链接:http://www.entityframeworktutorial.net/basics/entity-states.aspx 在实体的生命周期中,EF API维护着每一个实体的状态,对于 ...

  6. EF中的开放式并发(EF基础系列--28)

    好久没更新EF这个系列了,现在又重新开始. 这次学习,开放式并发.首先拿出数据库脚本: 说明一下,这个数据库脚本是之前的章节中稍作修改的: USE [SchoolDB] GO /****** Obje ...

  7. 9.翻译:EF基础系列---使用EF开发的方式有哪些?

    原文链接:http://www.entityframeworktutorial.net/choosing-development-approach-with-entity-framework.aspx ...

  8. 4.翻译:EF基础系列--EF架构

    原文地址:http://www.entityframeworktutorial.net/EntityFramework-Architecture.aspx 下面的图形,展示了EF的总体架构: 让我们来 ...

  9. 3.翻译:EF基础系列--EF怎么工作的?

    原文链接:http://www.entityframeworktutorial.net/basics/how-entity-framework-works.aspx 这里,你将会大概了解到EF是怎么工 ...

随机推荐

  1. Codeforces Round #385 (Div. 2) B - Hongcow Solves A Puzzle 暴力

    B - Hongcow Solves A Puzzle 题目连接: http://codeforces.com/contest/745/problem/B Description Hongcow li ...

  2. 【jquery】jquery.cookie.js 的使用指南

    之前有写过一篇原生 js 的 cookie 介绍,并且最后封装成 cookie.js 具体内容点击传送门. jquery.cookie.js 是一款轻量级的 cookie 插件,可以读取,写入和删除 ...

  3. java -jar shell 启动、停止

    启用 vi start.sh #!/bin/sh # ################################################################## # Powe ...

  4. 单源最短路径算法---Dijkstra

    Dijkstra算法树解决有向图G=(V,E)上带权的单源最短路径问题,但是要求所有边的权值非负. 解题思路: V表示有向图的所有顶点集合,S表示那么一些顶点结合,从源点s到该集合中的顶点的最终最短路 ...

  5. Hadoop2.x源码-编译剖析

    1.概述 最近,有小伙伴涉及到源码编译.然而,在编译期间也是遇到各种坑,在求助于搜索引擎,技术博客,也是难以解决自身所遇到的问题.笔者在被询问多次的情况下,今天打算为大家来写一篇文章来剖析下编译的细节 ...

  6. 论一次iOS面试

    最近觉得现在所在公司平台用户量太少,自身技术已经到了一个瓶颈,是时候需要换一个用户量多的平台,好好研究下iOS的性能优化.内存优化等问题了. 所面试的公司由于一些默认的规定,就不多说了,大致是面了一个 ...

  7. 结合使用saiku、mondrian workbentch建立多维查询报表

    1.简介 前几篇博客已经介绍了saiku.mondrian.MDX和模式文件他们之间的关系,那么如何将它们串联起来,供产品人员使用哪?下面咱们一步一步的实现 2.建立数据表 建表语句参考:http:/ ...

  8. ORACLE自定义顺序排序-转

    ORACLE可以借助DECODE函数,自定义顺序排序: select * from ( select 'Nick' as item from dual union all select 'Viki' ...

  9. {转}Unity3d+Jenkins 自动编译iOS、Android版本(U3D远程自动打包工具)

    http://www.cnblogs.com/yinghuochong/archive/2013/09/01/3294940.html

  10. JavaScript - 2个等号与3个等号的区别

    简言之,== equality 等同,=== identity 恒等. ==, 两边值类型不同的时候,要先进行类型转换,再比较. ===,不做类型转换,类型不同的一定不等. 或: = 赋值运算符 == ...