Entity Framework Tutorial Basics(17):DBSet Class
DBSet Class
DBSet class represents an entity set that is used for create, read, update, and delete operations. A generic version of DBSet (DbSet<TEntity>) can be used when the type of entity is not known at build time.
You can get the reference of DBSet by using DBContext, eg. dbcontext.Students, dbcontext.Standards, or any other entity set. DbContext class includes DbSet as shown below:
Some of the important methods of DBSet class are shown in the table below::
| 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: |
| 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: |
| Attach(Entity) | Entity which was passed as parameter | Attaches the given entity to the context in the Unchanged state
Example: |
| 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: |
| 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: |
| Include | DBQuery | Returns the included non generic LINQ to Entities query against a DbContext. (Inherited from DbQuery)
Example: |
| 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: |
| 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: |
Visit MSND for more information on DBSet class.
Entity Framework Tutorial Basics(17):DBSet Class的更多相关文章
- Entity Framework Tutorial Basics(1):Introduction
以下系列文章为Entity Framework Turial Basics系列 http://www.entityframeworktutorial.net/EntityFramework5/enti ...
- Entity Framework Tutorial Basics(4):Setup Entity Framework Environment
Setup Entity Framework Environment: Entity Framework 5.0 API was distributed in two places, in NuGet ...
- Entity Framework Tutorial Basics(43):Download Sample Project
Download Sample Project: Download sample project for basic Entity Framework tutorials. Sample projec ...
- Entity Framework Tutorial Basics(42):Colored Entity
Colored Entity in Entity Framework 5.0 You can change the color of an entity in the designer so that ...
- Entity Framework Tutorial Basics(41):Multiple Diagrams
Multiple Diagrams in Entity Framework 5.0 Visual Studio 2012 provides a facility to split the design ...
- Entity Framework Tutorial Basics(37):Lazy Loading
Lazy Loading: One of the important functions of Entity Framework is lazy loading. Lazy loading means ...
- Entity Framework Tutorial Basics(36):Eager Loading
Eager Loading: Eager loading is the process whereby a query for one type of entity also loads relate ...
- Entity Framework Tutorial Basics(34):Table-Valued Function
Table-Valued Function in Entity Framework 5.0 Entity Framework 5.0 supports Table-valued functions o ...
- Entity Framework Tutorial Basics(33):Spatial Data type support in Entity Framework 5.0
Spatial Data type support in Entity Framework 5.0 MS SQL Server 2008 introduced two spatial data typ ...
随机推荐
- url字符串中含中文的转码方法
凡是用get方法的,url里含中文的,都需要调用上面的函数进行编码.要不然会被当成二进制截断. //URL编码 +(NSString*)urlEncode:(NSString *)str { int ...
- shell while的用法
1. #!/bin/shint=1while (( "$int < 10" ))doecho "$int"let "int++"don ...
- PKU campus 2018 A Wife——差分约束?/dp
题目:http://poj.openjudge.cn/campus2018/A 有正规的差分约束做法,用到矩阵转置等等. 但也有简单(?)的dp做法. 有一个结论(?):一定要么在一天一点也不选,要么 ...
- linux swap交换分区说明/管理
https://coolnull.com/3699.html 一.SWAP说明1.1 SWAP概述当系统的物理内存不够用的时候,就需要将物理内存中的一部分空间释放出来,以供当前运行的程序使用.那些被释 ...
- boost1_55_0编译和安装
1.在www.boost.org下载文件并解压 2.进行解压目录 2.1 编译前的配置工作 执行bootstrap.bat windows 使用vs2010: 修改\boost_1_55_0\too ...
- java继承实例基础
总结:多态.重写.构造方法调用 package com.a; public class fsd { int a = 23; public fsd() { System.out.println(4444 ...
- AngularJS:应用
ylbtech-AngularJS:应用 1.返回顶部 1. AngularJS 应用 现在是时候创建一个真正的 AngularJS 单页 Web 应用(single page web applica ...
- CTF中常见文件的文件头(十六进制)
jpg/jpeg FF D8 FF E0 或 FF D8 FF E1 或 FF D8 FF E8 png 89 50 4E 47 bmp 42 4D 36 5D gif 47 49 46 38 zip ...
- MessageBox如何输出整数
int cx=10;CString s;s.Format(_T("整数是:%d"),cx);MessageBox(s);
- Java中Object.hashCode contract
面试时在这个问题上犯了个错误,只重写了equals方法,而没有覆盖hashCode()方法. 回来重读了Effective Java的Item 9,里面提到Object.hashCode contra ...