Entity Framework - SPLessons

Entity Framework DBSet Class

Home > Lesson > Chapter 9
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Entity Framework DBSet Class

Entity Framework DBSet Class

DBSet Class

shape Description

DBSet Class is used to represent a table. DBSet<TEntity> is used when the type of entity is not known at the building time.

shape Example

The following figure shows you the example for the DBSet.

Methods of DBSet Class

shape Methods

The following are the different methods supported by DBSet Class.
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 teh changes are saved, the objectstate changes to Unchanged.
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.
Find(int) Entity type Uses the primary key value to attempt to find an entity ttracked by the context.
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.
SqlQuery DBSqlQuery Creates a raw SQL query that will return entities in this set.