Export (0) Print
Expand All

DbSet<TEntity> Class

Entity Framework 5.0

Represents a typed entity set that is used to perform create, read, update, and delete operations. DbSet is not publicly constructible and can only be created from a DbContext instance.

System.Object
  System.Data.Entity.Infrastructure.DbQuery<TEntity>
    System.Data.Entity.DbSet<TEntity>

Namespace:  System.Data.Entity
Assembly:  EntityFramework (in EntityFramework.dll)

public class DbSet<TEntity> : DbQuery<TEntity>, 
	IDbSet<TEntity>, IQueryable<TEntity>, IEnumerable<TEntity>, 
	IQueryable, IEnumerable 
where TEntity : class

Type Parameters

TEntity

The type that defines the set. The type can be derived type as well as base type.

The DbSet<TEntity> type exposes the following members.

  NameDescription
Public propertyLocalReturns ObservableCollection<T> that represents entities of the set that are currently being tracked by the context and have not been marked as Deleted. Accessing the Local property never causes a query to be sent to the database. This property is usually used after a query has already been executed.
Top

  NameDescription
Public methodAddAdds 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.
Public methodAsNoTrackingReturns a new query where the entities returned will not be cached in the DbContext. (Inherited from DbQuery<TResult>.)
Public methodAttachAttaches the given entity to the context in the Unchanged
Public methodCreate()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 methodCreate<TDerivedEntity>()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 methodEqualsReturns whether the specified object is equal to the current set. (Overrides DbQuery<TResult>.Equals(Object).)
Protected methodFinalize (Inherited from Object.)
Public methodFindUses 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.
Public methodGetHashCodeReturns the hash fucntion for the specified set. (Overrides DbQuery<TResult>.GetHashCode().)
Public methodGetTypeGets the type for the current set.
Public methodIncludeReturns the included LINQ to entities query against a DbContext. (Inherited from DbQuery<TResult>.)
Protected methodMemberwiseClone (Inherited from Object.)
Public methodRemoveMarks 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 methodSqlQueryCreates 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 methodToStringReturns a String representation of the underlying query. (Inherited from DbQuery<TResult>.)
Top

  NameDescription
Public operatorStatic memberImplicit(DbSet<TEntity> to DbSet)Returns the equivalent non-generic DbSet.
Top

  NameDescription
Public Extension MethodAddOrUpdate<TEntity>(TEntity[])Overloaded. Adds or updates entities by key when SaveChanges is called. Equivalent to an "upsert" operation from database terminology. This method can be useful when seeding data using Migrations. (Defined by IDbSetExtensions.)
Public Extension MethodAddOrUpdate<TEntity>(Expression<Func<TEntity, Object>>, TEntity[])Overloaded. Adds or updates entities by key when SaveChanges is called. Equivalent to an "upsert" operation from database terminology. This method can be useful when seeding data using Migrations. (Defined by IDbSetExtensions.)
Public Extension MethodAsNoTracking<TEntity>Returns a new query where the entities returned will not be cached in the DbContext or ObjectContext. (Defined by DbExtensions.)
Public Extension MethodInclude<TEntity>(String)Overloaded. Specifies the related objects to include in the query results. (Defined by DbExtensions.)
Public Extension MethodInclude<TEntity, TProperty>(Expression<Func<TEntity, TProperty>>)Overloaded. Specifies the related objects to include in the query results. (Defined by DbExtensions.)
Public Extension MethodLoadAn extension method on IQueryable that enumerates the results of the query. This is equivalent to calling ToList without actually creating the list. (Defined by DbExtensions.)
Top

  NameDescription
Explicit interface implemetationPrivate propertyIListSource.ContainsListCollectionReturns false. (Inherited from DbQuery<TResult>.)
Explicit interface implemetationPrivate propertyIQueryable.ElementTypeThe IQueryable element type. (Inherited from DbQuery<TResult>.)
Explicit interface implemetationPrivate propertyIQueryable.ExpressionThe IQueryable LINQ Expression. (Inherited from DbQuery<TResult>.)
Explicit interface implemetationPrivate methodIEnumerable<TResult>.GetEnumeratorGets the enumeration of this query causing it to be executed against the store. (Inherited from DbQuery<TResult>.)
Explicit interface implemetationPrivate methodIEnumerable.GetEnumeratorGets the enumeration of this query causing it to be executed against the store. (Inherited from DbQuery<TResult>.)
Explicit interface implemetationPrivate methodIListSource.GetListThrows an exception indicating that binding directly to a store query is not supported. (Inherited from DbQuery<TResult>.)
Explicit interface implemetationPrivate propertyIQueryable.ProviderThe IQueryable provider. (Inherited from DbQuery<TResult>.)
Top

DbSet implements IQueryable so that it can be used with LINQ. All query functionality is delegated to the existing LINQ to Entities provider.

DbSet does not support the Entity SQL methods.

DbSet does not support MEST (Multiple Entity Sets per Type) meaning that there is always a one-to-one correlation between a type and a set.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft