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 ...
随机推荐
- redis实战之事务与持久化
1. 事务描述 (1)什么是事务 事务,就是把一堆事情绑在一起,按顺序的执行,都成功了才算完成,否则恢复之前的样子 事务必须服从ACID原则,ACID原则分别是原子性(atomicity).一致性(c ...
- itext生成pdf(附带页眉,页脚,页码)
package cn.picclife.mwx.salesupport.marketactivity.util; import java.io.File; import java.io.FileOut ...
- tests
test
- LeetCode Number of Longest Increasing Subsequence
原题链接在这里:https://leetcode.com/problems/number-of-longest-increasing-subsequence/description/ 题目: Give ...
- Unity之将Texture保存成png
http://blog.csdn.net/bingheliefeng/article/details/51177505 using UnityEngine;using System.Collectio ...
- ASP.NET MVC 缓存Outputcache (局部动态)
首先说一下需求: 比如我需要对网站首页做缓存,于是在首页对于的Action上贴上了Outputcache,接着问题就来了,首页上的有部分数据是不能做缓存的,比如个人信息,不然,每个人登陆都是看到第一个 ...
- Python利用itchat库向好友或者公众号发消息
首先获得好友或者公众号的UserName 1.获取好友UserName #coding=utf8 import itchat itchat.auto_login(hotReload=True) #想给 ...
- [转]java 中的序列化是什么意思?有什么好处?
1.序列化是干什么的? 简单说就是为了保存在内存中的各种对象的状态,并且可以把保存的对象状态再读出来.虽然你可以用你自己的各种各样的方法来保存Object States,但是Java给你提供一种应该比 ...
- Tiny4412 u-boot分析(2)u-boot启动流程
从大方面来说,u-boot的启动分成两个阶段,第一个阶段主要的职责是准备初始化的环境,主要有以下几点 ①设置异常向量表 ②把CPU的工作模式设置为SVC32模式 ③关闭中断.MMU和cache ④关闭 ...
- Django之时区
在settings.py中修改如下配置: TIME_ZONE = 'Asia/Shanghai' USE_I18N = True USE_L10N = True USE_TZ = False 这样在m ...