IDbSet<TEntity> Interface

Definition

An IDbSet<TEntity> represents the collection of all entities in the context, or that can be queried from the database, of a given type. DbSet<TEntity> is a concrete implementation of IDbSet.

[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix", Justification="Name is intentional")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", Justification="Casing is intentional")]
public interface IDbSet<TEntity> : System.Collections.Generic.IEnumerable<TEntity>, System.Linq.IQueryable<TEntity> where TEntity : class
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix", Justification="Name is intentional")]
public interface IDbSet<TEntity> : System.Collections.Generic.IEnumerable<TEntity>, System.Linq.IQueryable<TEntity> where TEntity : class
type IDbSet<'Entity (requires 'Entity : null)> = interface
    interface IQueryable<'Entity (requires 'Entity : null)>
    interface seq<'Entity (requires 'Entity : null)>
    interface IQueryable
    interface IEnumerable
Public Interface IDbSet(Of TEntity)
Implements IEnumerable(Of TEntity), IQueryable(Of TEntity)

Type Parameters

TEntity

The type that defines the set.

Derived
Attributes
Implements

Remarks

IDbSet<TEntity> was originally intended to allow creation of test doubles (mocks or fakes) for DbSet<TEntity>. However, this approach has issues in that adding new members to an interface breaks existing code that already implements the interface without the new members. Therefore, starting with EF6, no new members will be added to this interface and it is recommended that DbSet<TEntity> be used as the base class for test doubles.

Properties

Local

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.

Methods

Add(TEntity)

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.

Attach(TEntity)

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.

Create()

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.

Create<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. 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.

Find(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.

Remove(TEntity)

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.

Extension Methods

AsNoTracking<T>(IQueryable<T>)

Returns a new query where the entities returned will not be cached in the DbContext or ObjectContext. This method works by calling the AsNoTracking method of the underlying query object. If the underlying query object does not have a AsNoTracking method, then calling this method will have no affect.

Include<T>(IQueryable<T>, String)
Include<T,TProperty>(IQueryable<T>, Expression<Func<T,TProperty>>)
AddOrUpdate<TEntity>(IDbSet<TEntity>, TEntity[])

Adds or updates entities by key when SaveChanges is called. Equivalent to an "upsert" operation from database terminology. This method can useful when seeding data using Migrations.

AddOrUpdate<TEntity>(IDbSet<TEntity>, Expression<Func<TEntity,Object>>, TEntity[])

Adds or updates entities by a custom identification expression when SaveChanges is called. Equivalent to an "upsert" operation from database terminology. This method can useful when seeding data using Migrations.

AddOrUpdate<TEntity>(IDbSet<TEntity>, TEntity[])

Adds or updates entities by key when SaveChanges is called. Equivalent to an "upsert" operation from database terminology. This method can useful when seeding data using Migrations.

AddOrUpdate<TEntity>(IDbSet<TEntity>, Expression<Func<TEntity,Object>>, TEntity[])

Adds or updates entities by a custom identification expression when SaveChanges is called. Equivalent to an "upsert" operation from database terminology. This method can useful when seeding data using Migrations.

AllAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>, CancellationToken)

Asynchronously determines whether all the elements of a sequence satisfy a condition.

AllAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>)

Asynchronously determines whether all the elements of a sequence satisfy a condition.

AnyAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>, CancellationToken)

Asynchronously determines whether any element of a sequence satisfies a condition.

AnyAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>)

Asynchronously determines whether any element of a sequence satisfies a condition.

AnyAsync<TSource>(IQueryable<TSource>, CancellationToken)

Asynchronously determines whether a sequence contains any elements.

AnyAsync<TSource>(IQueryable<TSource>)

Asynchronously determines whether a sequence contains any elements.

AsNoTracking<T>(IQueryable<T>)

Returns a new query where the entities returned will not be cached in the DbContext or ObjectContext. This method works by calling the AsNoTracking method of the underlying query object. If the underlying query object does not have an AsNoTracking method, then calling this method will have no affect.

AsStreaming<T>(IQueryable<T>)
Obsolete.

Returns a new query that will stream the results instead of buffering. This method works by calling the AsStreaming method of the underlying query object. If the underlying query object does not have an AsStreaming method, then calling this method will have no affect.

AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Decimal>>, CancellationToken)

Asynchronously computes the average of a sequence of Decimal values that is obtained by invoking a projection function on each element of the input sequence.

AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Decimal>>)

Asynchronously computes the average of a sequence of Decimal values that is obtained by invoking a projection function on each element of the input sequence.

AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Double>>, CancellationToken)

Asynchronously computes the average of a sequence of Double values that is obtained by invoking a projection function on each element of the input sequence.

AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Double>>)

Asynchronously computes the average of a sequence of Double values that is obtained by invoking a projection function on each element of the input sequence.

AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>, CancellationToken)

Asynchronously computes the average of a sequence of Int32 values that is obtained by invoking a projection function on each element of the input sequence.

AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>)

Asynchronously computes the average of a sequence of Int32 values that is obtained by invoking a projection function on each element of the input sequence.

AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int64>>, CancellationToken)

Asynchronously computes the average of a sequence of Int64 values that is obtained by invoking a projection function on each element of the input sequence.

AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int64>>)

Asynchronously computes the average of a sequence of Int64 values that is obtained by invoking a projection function on each element of the input sequence.

AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Decimal>>>, CancellationToken)

Asynchronously computes the average of a sequence of nullable Decimal values that is obtained by invoking a projection function on each element of the input sequence.

AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Decimal>>>)

Asynchronously computes the average of a sequence of nullable Decimal values that is obtained by invoking a projection function on each element of the input sequence.

AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Double>>>, CancellationToken)

Asynchronously computes the average of a sequence of nullable Double values that is obtained by invoking a projection function on each element of the input sequence.

AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Double>>>)

Asynchronously computes the average of a sequence of nullable Double values that is obtained by invoking a projection function on each element of the input sequence.

AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Int32>>>, CancellationToken)

Asynchronously computes the average of a sequence of nullable Int32 values that is obtained by invoking a projection function on each element of the input sequence.

AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Int32>>>)

Asynchronously computes the average of a sequence of nullable Int32 values that is obtained by invoking a projection function on each element of the input sequence.

AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Int64>>>, CancellationToken)

Asynchronously computes the average of a sequence of nullable Int64 values that is obtained by invoking a projection function on each element of the input sequence.

AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Int64>>>)

Asynchronously computes the average of a sequence of nullable Int64 values that is obtained by invoking a projection function on each element of the input sequence.

AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Single>>>, CancellationToken)

Asynchronously computes the average of a sequence of nullable Single values that is obtained by invoking a projection function on each element of the input sequence.

AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Single>>>)

Asynchronously computes the average of a sequence of nullable Single values that is obtained by invoking a projection function on each element of the input sequence.

AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Single>>, CancellationToken)

Asynchronously computes the average of a sequence of Single values that is obtained by invoking a projection function on each element of the input sequence.

AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Single>>)

Asynchronously computes the average of a sequence of Single values that is obtained by invoking a projection function on each element of the input sequence.

ContainsAsync<TSource>(IQueryable<TSource>, TSource, CancellationToken)

Asynchronously determines whether a sequence contains a specified element by using the default equality comparer.

ContainsAsync<TSource>(IQueryable<TSource>, TSource)

Asynchronously determines whether a sequence contains a specified element by using the default equality comparer.

CountAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>, CancellationToken)

Asynchronously returns the number of elements in a sequence that satisfy a condition.

CountAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>)

Asynchronously returns the number of elements in a sequence that satisfy a condition.

CountAsync<TSource>(IQueryable<TSource>, CancellationToken)

Asynchronously returns the number of elements in a sequence.

CountAsync<TSource>(IQueryable<TSource>)

Asynchronously returns the number of elements in a sequence.

FirstAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>, CancellationToken)

Asynchronously returns the first element of a sequence that satisfies a specified condition.

FirstAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>)

Asynchronously returns the first element of a sequence that satisfies a specified condition.

FirstAsync<TSource>(IQueryable<TSource>, CancellationToken)

Asynchronously returns the first element of a sequence.

FirstAsync<TSource>(IQueryable<TSource>)

Asynchronously returns the first element of a sequence.

FirstOrDefaultAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>, CancellationToken)

Asynchronously returns the first element of a sequence that satisfies a specified condition or a default value if no such element is found.

FirstOrDefaultAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>)

Asynchronously returns the first element of a sequence that satisfies a specified condition or a default value if no such element is found.

FirstOrDefaultAsync<TSource>(IQueryable<TSource>, CancellationToken)

Asynchronously returns the first element of a sequence, or a default value if the sequence contains no elements.

FirstOrDefaultAsync<TSource>(IQueryable<TSource>)

Asynchronously returns the first element of a sequence, or a default value if the sequence contains no elements.

ForEachAsync<T>(IQueryable<T>, Action<T>, CancellationToken)

Asynchronously enumerates the query results and performs the specified action on each element.

ForEachAsync<T>(IQueryable<T>, Action<T>)

Asynchronously enumerates the query results and performs the specified action on each element.

Include<T>(IQueryable<T>, String)

Specifies the related objects to include in the query results.

Include<T,TProperty>(IQueryable<T>, Expression<Func<T,TProperty>>)

Specifies the related objects to include in the query results.

LongCountAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>, CancellationToken)

Asynchronously returns an Int64 that represents the number of elements in a sequence that satisfy a condition.

LongCountAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>)

Asynchronously returns an Int64 that represents the number of elements in a sequence that satisfy a condition.

LongCountAsync<TSource>(IQueryable<TSource>, CancellationToken)

Asynchronously returns an Int64 that represents the total number of elements in a sequence.

LongCountAsync<TSource>(IQueryable<TSource>)

Asynchronously returns an Int64 that represents the total number of elements in a sequence.

MaxAsync<TSource>(IQueryable<TSource>, CancellationToken)

Asynchronously returns the maximum value of a sequence.

MaxAsync<TSource>(IQueryable<TSource>)

Asynchronously returns the maximum value of a sequence.

MaxAsync<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>, CancellationToken)

Asynchronously invokes a projection function on each element of a sequence and returns the maximum resulting value.

MaxAsync<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>)

Asynchronously invokes a projection function on each element of a sequence and returns the maximum resulting value.

MinAsync<TSource>(IQueryable<TSource>, CancellationToken)

Asynchronously returns the minimum value of a sequence.

MinAsync<TSource>(IQueryable<TSource>)

Asynchronously returns the minimum value of a sequence.

MinAsync<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>, CancellationToken)

Asynchronously invokes a projection function on each element of a sequence and returns the minimum resulting value.

MinAsync<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>)

Asynchronously invokes a projection function on each element of a sequence and returns the minimum resulting value.

SingleAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>, CancellationToken)

Asynchronously returns the only element of a sequence that satisfies a specified condition, and throws an exception if more than one such element exists.

SingleAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>)

Asynchronously returns the only element of a sequence that satisfies a specified condition, and throws an exception if more than one such element exists.

SingleAsync<TSource>(IQueryable<TSource>, CancellationToken)

Asynchronously returns the only element of a sequence, and throws an exception if there is not exactly one element in the sequence.

SingleAsync<TSource>(IQueryable<TSource>)

Asynchronously returns the only element of a sequence, and throws an exception if there is not exactly one element in the sequence.

SingleOrDefaultAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>, CancellationToken)

Asynchronously returns the only element of a sequence that satisfies a specified condition or a default value if no such element exists; this method throws an exception if more than one element satisfies the condition.

SingleOrDefaultAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>)

Asynchronously returns the only element of a sequence that satisfies a specified condition or a default value if no such element exists; this method throws an exception if more than one element satisfies the condition.

SingleOrDefaultAsync<TSource>(IQueryable<TSource>, CancellationToken)

Asynchronously returns the only element of a sequence, or a default value if the sequence is empty; this method throws an exception if there is more than one element in the sequence.

SingleOrDefaultAsync<TSource>(IQueryable<TSource>)

Asynchronously returns the only element of a sequence, or a default value if the sequence is empty; this method throws an exception if there is more than one element in the sequence.

Skip<TSource>(IQueryable<TSource>, Expression<Func<Int32>>)

Bypasses a specified number of elements in a sequence and then returns the remaining elements.

SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Decimal>>, CancellationToken)

Asynchronously computes the sum of the sequence of Decimal values that is obtained by invoking a projection function on each element of the input sequence.

SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Decimal>>)

Asynchronously computes the sum of the sequence of Decimal values that is obtained by invoking a projection function on each element of the input sequence.

SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Double>>, CancellationToken)

Asynchronously computes the sum of the sequence of Double values that is obtained by invoking a projection function on each element of the input sequence.

SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Double>>)

Asynchronously computes the sum of the sequence of Double values that is obtained by invoking a projection function on each element of the input sequence.

SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>, CancellationToken)

Asynchronously computes the sum of the sequence of Int32 values that is obtained by invoking a projection function on each element of the input sequence.

SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>)

Asynchronously computes the sum of the sequence of Int32 values that is obtained by invoking a projection function on each element of the input sequence.

SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int64>>, CancellationToken)

Asynchronously computes the sum of the sequence of Int64 values that is obtained by invoking a projection function on each element of the input sequence.

SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int64>>)

Asynchronously computes the sum of the sequence of Int64 values that is obtained by invoking a projection function on each element of the input sequence.

SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Decimal>>>, CancellationToken)

Asynchronously computes the sum of the sequence of nullable Decimal values that is obtained by invoking a projection function on each element of the input sequence.

SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Decimal>>>)

Asynchronously computes the sum of the sequence of nullable Decimal values that is obtained by invoking a projection function on each element of the input sequence.

SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Double>>>, CancellationToken)

Asynchronously computes the sum of the sequence of nullable Double values that is obtained by invoking a projection function on each element of the input sequence.

SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Double>>>)

Asynchronously computes the sum of the sequence of nullable Double values that is obtained by invoking a projection function on each element of the input sequence.

SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Int32>>>, CancellationToken)

Asynchronously computes the sum of the sequence of nullable Int32 values that is obtained by invoking a projection function on each element of the input sequence.

SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Int32>>>)

Asynchronously computes the sum of the sequence of nullable Int32 values that is obtained by invoking a projection function on each element of the input sequence.

SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Int64>>>, CancellationToken)

Asynchronously computes the sum of the sequence of nullable Int64 values that is obtained by invoking a projection function on each element of the input sequence.

SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Int64>>>)

Asynchronously computes the sum of the sequence of nullable Int64 values that is obtained by invoking a projection function on each element of the input sequence.

SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Single>>>, CancellationToken)

Asynchronously computes the sum of the sequence of nullable Single values that is obtained by invoking a projection function on each element of the input sequence.

SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Single>>>)

Asynchronously computes the sum of the sequence of nullable Single values that is obtained by invoking a projection function on each element of the input sequence.

SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Single>>, CancellationToken)

Asynchronously computes the sum of the sequence of Single values that is obtained by invoking a projection function on each element of the input sequence.

SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Single>>)

Asynchronously computes the sum of the sequence of Single values that is obtained by invoking a projection function on each element of the input sequence.

Take<TSource>(IQueryable<TSource>, Expression<Func<Int32>>)

Returns a specified number of contiguous elements from the start of a sequence.

ToArrayAsync<TSource>(IQueryable<TSource>, CancellationToken)

Creates an array from an IQueryable<T> by enumerating it asynchronously.

ToArrayAsync<TSource>(IQueryable<TSource>)

Creates an array from an IQueryable<T> by enumerating it asynchronously.

ToDictionaryAsync<TSource,TKey>(IQueryable<TSource>, Func<TSource,TKey>, IEqualityComparer<TKey>, CancellationToken)

Creates a Dictionary<TKey,TValue> from an IQueryable<T> by enumerating it asynchronously according to a specified key selector function and a comparer.

ToDictionaryAsync<TSource,TKey>(IQueryable<TSource>, Func<TSource,TKey>, IEqualityComparer<TKey>)

Creates a Dictionary<TKey,TValue> from an IQueryable<T> by enumerating it asynchronously according to a specified key selector function and a comparer.

ToDictionaryAsync<TSource,TKey>(IQueryable<TSource>, Func<TSource,TKey>, CancellationToken)

Creates a Dictionary<TKey,TValue> from an IQueryable<T> by enumerating it asynchronously according to a specified key selector function.

ToDictionaryAsync<TSource,TKey>(IQueryable<TSource>, Func<TSource,TKey>)

Creates a Dictionary<TKey,TValue> from an IQueryable<T> by enumerating it asynchronously according to a specified key selector function.

ToDictionaryAsync<TSource,TKey,TElement>(IQueryable<TSource>, Func<TSource,TKey>, Func<TSource,TElement>, IEqualityComparer<TKey>, CancellationToken)

Creates a Dictionary<TKey,TValue> from an IQueryable<T> by enumerating it asynchronously according to a specified key selector function, a comparer, and an element selector function.

ToDictionaryAsync<TSource,TKey,TElement>(IQueryable<TSource>, Func<TSource,TKey>, Func<TSource,TElement>, IEqualityComparer<TKey>)

Creates a Dictionary<TKey,TValue> from an IQueryable<T> by enumerating it asynchronously according to a specified key selector function, a comparer, and an element selector function.

ToDictionaryAsync<TSource,TKey,TElement>(IQueryable<TSource>, Func<TSource,TKey>, Func<TSource,TElement>, CancellationToken)

Creates a Dictionary<TKey,TValue> from an IQueryable<T> by enumerating it asynchronously according to a specified key selector and an element selector function.

ToDictionaryAsync<TSource,TKey,TElement>(IQueryable<TSource>, Func<TSource,TKey>, Func<TSource,TElement>)

Creates a Dictionary<TKey,TValue> from an IQueryable<T> by enumerating it asynchronously according to a specified key selector and an element selector function.

ToListAsync<TSource>(IQueryable<TSource>, CancellationToken)

Creates a List<T> from an IQueryable<T> by enumerating it asynchronously.

ToListAsync<TSource>(IQueryable<TSource>)

Creates a List<T> from an IQueryable<T> by enumerating it asynchronously.

Applies to