Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

DbSet Class

 

A non-generic version of DbSet<TEntity> which can be used when the type of entity is not known at build time.

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


[SuppressMessageAttribute("Microsoft.Design", "CA1010:CollectionsShouldImplementGenericInterface")]
[SuppressMessageAttribute("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix", 
	Justification = "Name is intentional")]
public ref class DbSet abstract : DbQuery

NameDescription
System_CAPS_protmethodDbSet()

Creates an instance of a DbSet when called from the constructor of a derived type that will be used as a test double for DbSets. Methods and properties that will be used by the test double must be implemented by the test double except AsNoTracking, AsStreaming, an Include where the default implementation is a no-op.

NameDescription
System_CAPS_pubpropertyElementType

The IQueryable element type.(Inherited from DbQuery.)

System_CAPS_pubpropertyLocal

Gets an ObservableCollection<T> that represents a local view of all Added, Unchanged, and Modified entities in this set. This local view will stay in sync as entities are added or removed from the context. Likewise, entities added to or removed from the local view will automatically be added to or removed from the context.

NameDescription
System_CAPS_pubmethodAdd(Object^)

Adds the given entity to the context underlying the set in the Added state such that it will be inserted into the database when SaveChanges is called.

System_CAPS_pubmethodAddRange(IEnumerable^)

Adds the given collection of entities into context underlying the set with each entity being put into the Added state such that it will be inserted into the database when SaveChanges is called.

System_CAPS_pubmethodAsNoTracking()

Returns a new query where the entities returned will not be cached in the DbContext.(Inherited from DbQuery.)

System_CAPS_pubmethodAsStreaming()

Obsolete.Returns a new query that will stream the results instead of buffering.(Inherited from DbQuery.)

System_CAPS_pubmethodAttach(Object^)

Attaches the given entity to the context underlying the set. That is, the entity is placed into the context in the Unchanged state, just as if it had been read from the database.

System_CAPS_pubmethodCast<TEntity>()

Returns the equivalent generic DbSet<TEntity> object.

System_CAPS_pubmethodCreate()

Creates a new instance of an entity for the type of this set. Note that 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.

System_CAPS_pubmethodCreate(Type^)

Creates a new instance of an entity for the type of this set or for a type derived from the type of this set. Note that 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.

System_CAPS_pubmethodEquals(Object^)

Returns whether the specified set is equal to the current set.(Overrides DbQuery::Equals(Object^).)

System_CAPS_protmethodFinalize()

(Inherited from Object.)

System_CAPS_pubmethodFind(array<Object^>^)

Finds an entity with the given primary key values. If an entity with the given primary key values exists in the context, then it is returned immediately without making a request to the store. Otherwise, a request is made to the store for an entity with the given primary key values and this entity, if found, is attached to the context and returned. If no entity is found in the context or the store, then null is returned.

System_CAPS_pubmethodFindAsync(CancellationToken, array<Object^>^)

Asynchronously finds an entity with the given primary key values. If an entity with the given primary key values exists in the context, then it is returned immediately without making a request to the store. Otherwise, a request is made to the store for an entity with the given primary key values and this entity, if found, is attached to the context and returned. If no entity is found in the context or the store, then null is returned.

System_CAPS_pubmethodFindAsync(array<Object^>^)

Asynchronously finds an entity with the given primary key values. If an entity with the given primary key values exists in the context, then it is returned immediately without making a request to the store. Otherwise, a request is made to the store for an entity with the given primary key values and this entity, if found, is attached to the context and returned. If no entity is found in the context or the store, then null is returned.

System_CAPS_pubmethodGetHashCode()

Returns the hash function for the specified set.(Overrides DbQuery::GetHashCode().)

System_CAPS_pubmethodGetType()

Gets the type for the current set.

System_CAPS_pubmethodInclude(String^)

Specifies the related objects to include in the query results.(Inherited from DbQuery.)

System_CAPS_protmethodMemberwiseClone()

(Inherited from Object.)

System_CAPS_pubmethodRemove(Object^)

Marks the given entity as Deleted such that it will be deleted from the database when SaveChanges is called. Note that the entity must exist in the context in some other state before this method is called.

System_CAPS_pubmethodRemoveRange(IEnumerable^)

Removes the given collection of entities from the context underlying the set with each entity being put into the Deleted state such that it will be deleted from the database when SaveChanges is called.

System_CAPS_pubmethodSqlQuery(String^, array<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 DbRawSqlQuery returned. Note that the entities returned are always of the type for this set and never of a derived type. If the table or tables queried may contain data for other entity types, then the SQL query must be written appropriately to ensure that only entities of the correct type are returned. As with any API that accepts SQL it is important to parameterize any user input to protect against a SQL injection attack. You can include parameter place holders in the SQL query string and then supply parameter values as additional arguments. Any parameter values you supply will automatically be converted to a DbParameter. context.Set(typeof(Blog)).SqlQuery("SELECT * FROM dbo.Posts WHERE Author = @p0", userSuppliedAuthor); Alternatively, you can also construct a DbParameter and supply it to SqlQuery. This allows you to use named parameters in the SQL query string. context.Set(typeof(Blog)).SqlQuery("SELECT * FROM dbo.Posts WHERE Author = @author", new SqlParameter("@author", userSuppliedAuthor));

System_CAPS_pubmethodToString()

Returns a String representation of the underlying query.(Inherited from DbQuery.)

NameDescription
System_CAPS_pubinterfaceSystem_CAPS_privmethodIEnumerable::GetEnumerator()

Returns an IEnumerator which when enumerated will execute the query against the database.(Inherited from DbQuery.)

System_CAPS_pubinterfaceSystem_CAPS_privmethodIListSource::GetList()

Throws an exception indicating that binding directly to a store query is not supported. Instead populate a DbSet with data, for example by using the Load extension method, and then bind to local data. For WPF bind to DbSet.Local. For Windows Forms bind to DbSet.Local.ToBindingList().(Inherited from DbQuery.)

System_CAPS_pubinterfaceSystem_CAPS_privmethodIDbAsyncEnumerable::GetAsyncEnumerator()

Returns an IDbAsyncEnumerator which when enumerated will execute the query against the database.(Inherited from DbQuery.)

NameDescription
System_CAPS_pubmethodForEachAsync(Action<Object^>^)

Overloaded. Asynchronously enumerates the query results and performs the specified action on each element.(Defined by QueryableExtensions.)

System_CAPS_pubmethodForEachAsync(Action<Object^>^, CancellationToken)

Overloaded. Asynchronously enumerates the query results and performs the specified action on each element.(Defined by QueryableExtensions.)

System_CAPS_pubmethodLoad()

Enumerates the query such that for server queries such as those of DbSet<TEntity>, ObjectSet<TEntity> , ObjectQuery<T>, and others the results of the query will be loaded into the associated DbContext , ObjectContext or other cache on the client. This is equivalent to calling ToList and then throwing away the list without the overhead of actually creating the list.(Defined by QueryableExtensions.)

System_CAPS_pubmethodLoadAsync()

Overloaded. Asynchronously enumerates the query such that for server queries such as those of DbSet<TEntity>, ObjectSet<TEntity> , ObjectQuery<T>, and others the results of the query will be loaded into the associated DbContext , ObjectContext or other cache on the client. This is equivalent to calling ToList and then throwing away the list without the overhead of actually creating the list.(Defined by QueryableExtensions.)

System_CAPS_pubmethodLoadAsync(CancellationToken)

Overloaded. Asynchronously enumerates the query such that for server queries such as those of DbSet<TEntity>, ObjectSet<TEntity> , ObjectQuery<T>, and others the results of the query will be loaded into the associated DbContext , ObjectContext or other cache on the client. This is equivalent to calling ToList and then throwing away the list without the overhead of actually creating the list.(Defined by QueryableExtensions.)

System_CAPS_pubmethodToListAsync()

Overloaded. Creates a List<T> from an IQueryable by enumerating it asynchronously.(Defined by QueryableExtensions.)

System_CAPS_pubmethodToListAsync(CancellationToken)

Overloaded. Creates a List<T> from an IQueryable by enumerating it asynchronously.(Defined by QueryableExtensions.)

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

Return to top
Show:
© 2015 Microsoft