Entity Framework - DBSet Class


DbSet class represents the collection of all the entities in the context, or that can be queried (create, read, update, and delete operations) from the database, of a given type. DbSet objects are created from a DbContext class using DbContext.Set method. System.Data.Entity namespace is used.
 

Methods

DBSet Class Method
Method Type Method Name Return Type Description
 Public method  Add  Added entity  object  Add the given entity to the context. When the changes are being saved, the  entities in  the Added states are inserted into the database. The object state  changes to  Unchanged after saving the changes.
 Public method  AsNoTracking  A new query with  NoTracking applied.  Returns a new query where the entities returned will not be cached in the  DbContext.
 Public method  Attach  Entity object  Attaches the given entity to the context in the Unchanged state.
 Public method  Cast<TEntity>  The generic set  object.DbSet<TEntity>  Returns the equivalent generic DbSet<TEntity> object.
 Public method  Create()  The entity instance,  which may be a proxy.  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.
 Public method  Create(Type)  The entity instance,  which may be a  proxy.   Creates a new instance of an entity for the type of this set or for a type derived  from  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.
 Public method  Equals  Boolean  Returns whether the specified set is equal to the current set. (Overrides  DbQuery.Equals(Object).)
 Protected  method  Finalize  void  Allows an object to free resources and perform other cleanup operations before it  is  reclaimed by garbage collection.
 Public method  Find  Entity object or null  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. Find also returns entities that have been  added to the context but  have not yet been saved to the database.
 Public method  GetHashCode  INT  Returns the hash function for the specified set. (Overrides  DbQuery.GetHashCode().)
 Public method  GetType  The type for the  current set.  Gets the type for the current set.
 Public method  Include  The included LINQ  query.  Returns the included non generic LINQ to Entities query against a DbContext. 
 Protected  method  MemberwiseClone   A shallow copy of the  current Object.  Creates a shallow copy of the current Object.
 Public method  Remove  The entity object.  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.
 Public method  SqlQuery       DbSqlQuery object  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  the DbSqlQuery<TEntity> returned from this method.
 Public method  ToString  string  Returns a String representation of the underlying query. (Inherited from  DbQuery.)

Praesent mattis

Pellentesque viverra vulputate enim. Aliquam erat volutpat. Pellentesque tristique ante ut risus. Quisque dictum. Integer nisl risus, sagittis convallis, rutrum id, elementum congue, nibh. Suspendisse dictum porta lectus. Donec placerat odio vel elit.

Read More