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. Android学习笔记----Activity的生命周期图示

    转载,一目了然.

  2. 阅读《Effective C++》系列

    <Effective C++>条款07:为多态基类声明virtual析构函数 这样做主要是为了防止内存泄漏,见我hexo博客. C++的虚析构函数 <Effective C++> ...

  3. javascript中apply()方法解析-简单易懂!

    今天看到了js的call与apply的异同,想着整理一下知识点,发现了一篇好文章,分享过来给大家,写的非常好! 参考: http://www.cnblogs.com/delin/archive/201 ...

  4. apk签名

    参考:http://stackoverflow.com/questions/13578134/how-to-automate-keystore-generation-using-the-java-ke ...

  5. 关于Parallel.For/Foreach并行方法中的localInit, body, localFinally使用

    对集合成员的操作往往可以通过并行来提高效率,.NET Parallel类提供了简单的方法来帮助我们实现这种并行,比如Paralle.For/ForEach/Invoke方法. 其中,For/ForEa ...

  6. 解决clone问题之外的体会

    adlnkoh.sh started at Thu Aug 25 15:42:51 CST 2016 Log file located at /u02/db/testdb/11.1.0/appsuti ...

  7. 30分钟入门Java8之默认方法和静态接口方法

    30分钟入门Java8之默认方法和静态接口方法 前言 上一篇文章30分钟入门Java8之lambda表达式,我们学习了lambda表达式.现在继续Java8新语言特性的学习,今天,我们要学习的是默认方 ...

  8. ubuntu 安装bochs

    //首先官网下载bochs源码wget http://bochs.sourceforge.net/svn-snapshot/bochs-20150503.tar.gz//然后解压 tar vxzf b ...

  9. sql like 时间

    and Convert(varchar(),TimeStamp,) like '%2013-09-06 09:46:03%'

  10. hessian入门

    hessian简介 Hessian是二进制的web service协议,官方网站提供Java.Flash/Flex.Python.C++..NET C#等实现.Hessian和Axis.XFire都能 ...