DbSet<TEntity> DbSet<TEntity> DbSet<TEntity> Class

Definition

A DbSet<TEntity> can be used to query and save instances of TEntity. LINQ queries against a DbSet<TEntity> will be translated into queries against the database.

The results of a LINQ query against a DbSet<TEntity> will contain the results returned from the database and may not reflect changes made in the context that have not been persisted to the database. For example, the results will not contain newly added entities and may still contain entities that are marked for deletion.

Depending on the database being used, some parts of a LINQ query against a DbSet<TEntity> may be evaluated in memory rather than being translated into a database query.

DbSet<TEntity> objects are usually obtained from a DbSet<TEntity> property on a derived DbContext or from the Set<TEntity>() method.

public abstract class DbSet<TEntity> : Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<IServiceProvider>, Microsoft.EntityFrameworkCore.Query.Internal.IAsyncEnumerableAccessor<TEntity>, System.Collections.Generic.IEnumerable<TEntity>, System.ComponentModel.IListSource, System.Linq.IQueryable, System.Linq.IQueryable<TEntity> where TEntity : class
type DbSet<'Entity (requires 'Entity : null)> = class
    interface IQueryable<'Entity (requires 'Entity : null)>
    interface seq<'Entity (requires 'Entity : null)>
    interface IEnumerable
    interface IQueryable
    interface IAsyncEnumerableAccessor<'Entity (requires 'Entity : null)>
    interface IInfrastructure<IServiceProvider>
    interface IListSource
Public MustInherit Class DbSet(Of TEntity)
Implements IAsyncEnumerableAccessor(Of TEntity), IEnumerable(Of TEntity), IInfrastructure(Of IServiceProvider), IListSource, IQueryable, IQueryable(Of TEntity)
Type Parameters
TEntity

The type of entity being operated on by this set.

Inheritance
DbSet<TEntity>DbSet<TEntity>DbSet<TEntity>
Derived
Implements

Constructors

DbSet<TEntity>() DbSet<TEntity>() DbSet<TEntity>()

Properties

Local Local Local

Gets an LocalView<TEntity> 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.

This property can be used for data binding by populating the set with data, for example by using the Load<TSource>(IQueryable<TSource>) extension method, and then binding to the local data through this property by calling ToObservableCollection() for WPF binding, or ToBindingList() for WinForms.

Methods

Add(TEntity) Add(TEntity) Add(TEntity)

Begins tracking the given entity, and any other reachable entities that are not already being tracked, in the Added state such that they will be inserted into the database when SaveChanges() is called.

AddAsync(TEntity, CancellationToken) AddAsync(TEntity, CancellationToken) AddAsync(TEntity, CancellationToken)

Begins tracking the given entity, and any other reachable entities that are not already being tracked, in the Added state such that they will be inserted into the database when SaveChanges() is called.

This method is async only to allow special value generators, such as the one used by 'Microsoft.EntityFrameworkCore.Metadata.SqlServerValueGenerationStrategy.SequenceHiLo', to access the database asynchronously. For all other cases the non async method should be used.

AddRange(IEnumerable<TEntity>) AddRange(IEnumerable<TEntity>) AddRange(IEnumerable<TEntity>)

Begins tracking the given entities, and any other reachable entities that are not already being tracked, in the Added state such that they will be inserted into the database when SaveChanges() is called.

AddRange(TEntity[]) AddRange(TEntity[]) AddRange(TEntity[])

Begins tracking the given entities, and any other reachable entities that are not already being tracked, in the Added state such that they will be inserted into the database when SaveChanges() is called.

AddRangeAsync(TEntity[]) AddRangeAsync(TEntity[]) AddRangeAsync(TEntity[])

Begins tracking the given entities, and any other reachable entities that are not already being tracked, in the Added state such that they will be inserted into the database when SaveChanges() is called.

This method is async only to allow special value generators, such as the one used by 'Microsoft.EntityFrameworkCore.Metadata.SqlServerValueGenerationStrategy.SequenceHiLo', to access the database asynchronously. For all other cases the non async method should be used.

AddRangeAsync(IEnumerable<TEntity>, CancellationToken) AddRangeAsync(IEnumerable<TEntity>, CancellationToken) AddRangeAsync(IEnumerable<TEntity>, CancellationToken)

Begins tracking the given entities, and any other reachable entities that are not already being tracked, in the Added state such that they will be inserted into the database when SaveChanges() is called.

This method is async only to allow special value generators, such as the one used by 'Microsoft.EntityFrameworkCore.Metadata.SqlServerValueGenerationStrategy.SequenceHiLo', to access the database asynchronously. For all other cases the non async method should be used.

Attach(TEntity) Attach(TEntity) Attach(TEntity)

Begins tracking the given entity in the Unchanged state such that no operation will be performed when SaveChanges() is called.

A recursive search of the navigation properties will be performed to find reachable entities that are not already being tracked by the context. These entities will also begin to be tracked by the context. If a reachable entity has its primary key value set then it will be tracked in the Unchanged state. If the primary key value is not set then it will be tracked in the Added state. An entity is considered to have its primary key value set if the primary key property is set to anything other than the CLR default for the property type.

AttachRange(IEnumerable<TEntity>) AttachRange(IEnumerable<TEntity>) AttachRange(IEnumerable<TEntity>)

Begins tracking the given entities in the Unchanged state such that no operation will be performed when SaveChanges() is called.

A recursive search of the navigation properties will be performed to find reachable entities that are not already being tracked by the context. These entities will also begin to be tracked by the context. If a reachable entity has its primary key value set then it will be tracked in the Unchanged state. If the primary key value is not set then it will be tracked in the Added state. An entity is considered to have its primary key value set if the primary key property is set to anything other than the CLR default for the property type.

AttachRange(TEntity[]) AttachRange(TEntity[]) AttachRange(TEntity[])

Begins tracking the given entities in the Unchanged state such that no operation will be performed when SaveChanges() is called.

A recursive search of the navigation properties will be performed to find reachable entities that are not already being tracked by the context. These entities will also begin to be tracked by the context. If a reachable entity has its primary key value set then it will be tracked in the Unchanged state. If the primary key value is not set then it will be tracked in the Added state. An entity is considered to have its primary key value set if the primary key property is set to anything other than the CLR default for the property type.

Equals(Object) Equals(Object) Equals(Object)

Determines whether the specified object is equal to the current object.

Find(Object[]) Find(Object[]) Find(Object[])

Finds an entity with the given primary key values. If an entity with the given primary key values is being tracked by the context, then it is returned immediately without making a request to the database. Otherwise, a query is made to the database 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, then null is returned.

FindAsync(Object[]) FindAsync(Object[]) FindAsync(Object[])

Finds an entity with the given primary key values. If an entity with the given primary key values is being tracked by the context, then it is returned immediately without making a request to the database. Otherwise, a query is made to the database 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, then null is returned.

FindAsync(Object[], CancellationToken) FindAsync(Object[], CancellationToken) FindAsync(Object[], CancellationToken)

Finds an entity with the given primary key values. If an entity with the given primary key values is being tracked by the context, then it is returned immediately without making a request to the database. Otherwise, a query is made to the database 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, then null is returned.

GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

Remove(TEntity) Remove(TEntity) Remove(TEntity)

Begins tracking the given entity in the Deleted state such that it will be removed from the database when SaveChanges() is called.

RemoveRange(IEnumerable<TEntity>) RemoveRange(IEnumerable<TEntity>) RemoveRange(IEnumerable<TEntity>)

Begins tracking the given entities in the Deleted state such that they will be removed from the database when SaveChanges() is called.

RemoveRange(TEntity[]) RemoveRange(TEntity[]) RemoveRange(TEntity[])

Begins tracking the given entities in the Deleted state such that they will be removed from the database when SaveChanges() is called.

ToString() ToString() ToString()

Returns a string that represents the current object.

Update(TEntity) Update(TEntity) Update(TEntity)

Begins tracking the given entity in the Modified state such that it will be updated in the database when SaveChanges() is called.

All properties of the entity will be marked as modified. To mark only some properties as modified, use Attach(TEntity) to begin tracking the entity in the Unchanged state and then use the returned EntityEntry to mark the desired properties as modified.

A recursive search of the navigation properties will be performed to find reachable entities that are not already being tracked by the context. These entities will also begin to be tracked by the context. If a reachable entity has its primary key value set then it will be tracked in the Modified state. If the primary key value is not set then it will be tracked in the Added state. An entity is considered to have its primary key value set if the primary key property is set to anything other than the CLR default for the property type.

UpdateRange(IEnumerable<TEntity>) UpdateRange(IEnumerable<TEntity>) UpdateRange(IEnumerable<TEntity>)

Begins tracking the given entities in the Modified state such that they will be updated in the database when SaveChanges() is called.

All properties of each entity will be marked as modified. To mark only some properties as modified, use Attach(TEntity) to begin tracking each entity in the Unchanged state and then use the returned EntityEntry to mark the desired properties as modified.

A recursive search of the navigation properties will be performed to find reachable entities that are not already being tracked by the context. These entities will also begin to be tracked by the context. If a reachable entity has its primary key value set then it will be tracked in the Modified state. If the primary key value is not set then it will be tracked in the Added state. An entity is considered to have its primary key value set if the primary key property is set to anything other than the CLR default for the property type.

UpdateRange(TEntity[]) UpdateRange(TEntity[]) UpdateRange(TEntity[])

Begins tracking the given entities in the Modified state such that they will be updated in the database when SaveChanges() is called.

All properties of each entity will be marked as modified. To mark only some properties as modified, use Attach(TEntity) to begin tracking each entity in the Unchanged state and then use the returned EntityEntry to mark the desired properties as modified.

A recursive search of the navigation properties will be performed to find reachable entities that are not already being tracked by the context. These entities will also begin to be tracked by the context. If a reachable entity has its primary key value set then it will be tracked in the Modified state. If the primary key value is not set then it will be tracked in the Added state. An entity is considered to have its primary key value set if the primary key property is set to anything other than the CLR default for the property type.

Explicit Interface Implementations

IInfrastructure<IServiceProvider>.Instance IInfrastructure<IServiceProvider>.Instance IInfrastructure<IServiceProvider>.Instance

Gets the scoped IServiceProvider being used to resolve services.

This property is intended for use by extension methods that need to make use of services not directly exposed in the public API surface.

IAsyncEnumerableAccessor<TEntity>.AsyncEnumerable IAsyncEnumerableAccessor<TEntity>.AsyncEnumerable IAsyncEnumerableAccessor<TEntity>.AsyncEnumerable

Returns an System.Collections.Generic.IAsyncEnumerable which when enumerated will asynchronously execute the query against the database.

IEnumerable<TEntity>.GetEnumerator() IEnumerable<TEntity>.GetEnumerator() IEnumerable<TEntity>.GetEnumerator()

Returns an IEnumerator<T> which when enumerated will execute a query against the database to load all entities from the database.

IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator()

Returns an IEnumerator which when enumerated will execute a query against the database to load all entities from the database.

IListSource.ContainsListCollection IListSource.ContainsListCollection IListSource.ContainsListCollection

Gets a value indicating whether the collection is a collection of System.Collections.IList objects. Always returns false.

IListSource.GetList() IListSource.GetList() IListSource.GetList()

This method is called by data binding frameworks when attempting to data bind directly to a DbSet<TEntity>.

This implementation always throws an exception as binding directly to a DbSet<TEntity> will result in a query being sent to the database every time the data binding framework requests the contents of the collection. Instead load the results into the context, for example, by using the Load<TSource>(IQueryable<TSource>) extension method, and then bind to the local data through the Local by calling ToObservableCollection() for WPF binding, or ToBindingList() for WinForms.

IQueryable.ElementType IQueryable.ElementType IQueryable.ElementType

Gets the IQueryable element type.

IQueryable.Expression IQueryable.Expression IQueryable.Expression

Gets the IQueryable LINQ Expression.

IQueryable.Provider IQueryable.Provider IQueryable.Provider

Gets the IQueryable provider.

Extension Methods

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

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

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

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

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

Asynchronously determines whether a sequence contains any elements.

AsNoTracking<TEntity>(IQueryable<TEntity>) AsNoTracking<TEntity>(IQueryable<TEntity>) AsNoTracking<TEntity>(IQueryable<TEntity>)

Returns a new query where the change tracker will not track any of the entities that are returned. If the entity instances are modified, this will not be detected by the change tracker and SaveChanges() will not persist those changes to the database.

Disabling change tracking is useful for read-only scenarios because it avoids the overhead of setting up change tracking for each entity instance. You should not disable change tracking if you want to manipulate entity instances and persist those changes to the database using SaveChanges().

Identity resolution will still be performed to ensure that all occurrences of an entity with a given key in the result set are represented by the same entity instance.

The default tracking behavior for queries can be controlled by QueryTrackingBehavior.

AsTracking<TEntity>(IQueryable<TEntity>) AsTracking<TEntity>(IQueryable<TEntity>) AsTracking<TEntity>(IQueryable<TEntity>)

Returns a new query where the change tracker will keep track of changes for all entities that are returned. Any modification to the entity instances will be detected and persisted to the database during SaveChanges().

The default tracking behavior for queries can be controlled by QueryTrackingBehavior.

AverageAsync(IQueryable<Decimal>, CancellationToken) AverageAsync(IQueryable<Decimal>, CancellationToken) AverageAsync(IQueryable<Decimal>, CancellationToken)

Asynchronously computes the average of a sequence of values.

AverageAsync(IQueryable<Double>, CancellationToken) AverageAsync(IQueryable<Double>, CancellationToken) AverageAsync(IQueryable<Double>, CancellationToken)

Asynchronously computes the average of a sequence of values.

AverageAsync(IQueryable<Int32>, CancellationToken) AverageAsync(IQueryable<Int32>, CancellationToken) AverageAsync(IQueryable<Int32>, CancellationToken)

Asynchronously computes the average of a sequence of values.

AverageAsync(IQueryable<Int64>, CancellationToken) AverageAsync(IQueryable<Int64>, CancellationToken) AverageAsync(IQueryable<Int64>, CancellationToken)

Asynchronously computes the average of a sequence of values.

AverageAsync(IQueryable<Nullable<Decimal>>, CancellationToken) AverageAsync(IQueryable<Nullable<Decimal>>, CancellationToken) AverageAsync(IQueryable<Nullable<Decimal>>, CancellationToken)

Asynchronously computes the average of a sequence of values.

AverageAsync(IQueryable<Nullable<Double>>, CancellationToken) AverageAsync(IQueryable<Nullable<Double>>, CancellationToken) AverageAsync(IQueryable<Nullable<Double>>, CancellationToken)

Asynchronously computes the average of a sequence of values.

AverageAsync(IQueryable<Nullable<Int32>>, CancellationToken) AverageAsync(IQueryable<Nullable<Int32>>, CancellationToken) AverageAsync(IQueryable<Nullable<Int32>>, CancellationToken)

Asynchronously computes the average of a sequence of values.

AverageAsync(IQueryable<Nullable<Int64>>, CancellationToken) AverageAsync(IQueryable<Nullable<Int64>>, CancellationToken) AverageAsync(IQueryable<Nullable<Int64>>, CancellationToken)

Asynchronously computes the average of a sequence of values.

AverageAsync(IQueryable<Nullable<Single>>, CancellationToken) AverageAsync(IQueryable<Nullable<Single>>, CancellationToken) AverageAsync(IQueryable<Nullable<Single>>, CancellationToken)

Asynchronously computes the average of a sequence of values.

AverageAsync(IQueryable<Single>, CancellationToken) AverageAsync(IQueryable<Single>, CancellationToken) AverageAsync(IQueryable<Single>, CancellationToken)

Asynchronously computes the average of a sequence of values.

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

Asynchronously computes the average of a sequence of 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) AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Double>>, CancellationToken) AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Double>>, CancellationToken)

Asynchronously computes the average of a sequence of 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) AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>, CancellationToken) AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>, CancellationToken)

Asynchronously computes the average of a sequence of 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) AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int64>>, CancellationToken) AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int64>>, CancellationToken)

Asynchronously computes the average of a sequence of 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) AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Decimal>>>, CancellationToken) AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Decimal>>>, CancellationToken)

Asynchronously computes the average of a sequence of 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) AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Double>>>, CancellationToken) AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Double>>>, CancellationToken)

Asynchronously computes the average of a sequence of 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) AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Int32>>>, CancellationToken) AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Int32>>>, CancellationToken)

Asynchronously computes the average of a sequence of 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) AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Int64>>>, CancellationToken) AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Int64>>>, CancellationToken)

Asynchronously computes the average of a sequence of 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) AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Single>>>, CancellationToken) AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Single>>>, CancellationToken)

Asynchronously computes the average of a sequence of 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) AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Single>>, CancellationToken) AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Single>>, CancellationToken)

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

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

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

CountAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>, CancellationToken) CountAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>, CancellationToken) 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>, CancellationToken) CountAsync<TSource>(IQueryable<TSource>, CancellationToken) CountAsync<TSource>(IQueryable<TSource>, CancellationToken)

Asynchronously returns the number of elements in a sequence.

FirstAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>, CancellationToken) FirstAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>, CancellationToken) 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>, CancellationToken) FirstAsync<TSource>(IQueryable<TSource>, CancellationToken) FirstAsync<TSource>(IQueryable<TSource>, CancellationToken)

Asynchronously returns the first element of a sequence.

FirstOrDefaultAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>, CancellationToken) FirstOrDefaultAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>, CancellationToken) 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>, CancellationToken) FirstOrDefaultAsync<TSource>(IQueryable<TSource>, CancellationToken) FirstOrDefaultAsync<TSource>(IQueryable<TSource>, CancellationToken)

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) ForEachAsync<T>(IQueryable<T>, Action<T>, CancellationToken) ForEachAsync<T>(IQueryable<T>, Action<T>, CancellationToken)

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

IgnoreQueryFilters<TEntity>(IQueryable<TEntity>) IgnoreQueryFilters<TEntity>(IQueryable<TEntity>) IgnoreQueryFilters<TEntity>(IQueryable<TEntity>)

Specifies that the current Entity Framework LINQ query should not have any model-level entity query filters applied.

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

Specifies related entities to include in the query results. The navigation property to be included is specified starting with the type of entity being queried (TEntity). Further navigation properties to be included can be appended, separated by the '.' character.

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

Specifies related entities to include in the query results. The navigation property to be included is specified starting with the type of entity being queried (TEntity). If you wish to include additional types based on the navigation properties of the type being included, then chain a call to ThenInclude<TEntity,TPreviousProperty,TProperty>(IIncludableQueryable<TEntity,IEnumerable<TPreviousProperty>>, Expression<Func<TPreviousProperty,TProperty>>) after this call.

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

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

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

Asynchronously returns the last element of a sequence.

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

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

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

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

Load<TSource>(IQueryable<TSource>) Load<TSource>(IQueryable<TSource>) Load<TSource>(IQueryable<TSource>)

Enumerates the query. When using Entity Framework, this causes the results of the query to be loaded into the associated context. This is equivalent to calling ToList and then throwing away the list (without the overhead of actually creating the list).

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

Asynchronously enumerates the query. When using Entity Framework, this causes the results of the query to be loaded into the associated context. This is equivalent to calling ToList and then throwing away the list (without the overhead of actually creating the list).

LongCountAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>, CancellationToken) LongCountAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>, CancellationToken) 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>, CancellationToken) LongCountAsync<TSource>(IQueryable<TSource>, CancellationToken) LongCountAsync<TSource>(IQueryable<TSource>, CancellationToken)

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

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

Asynchronously returns the maximum value of a sequence.

MaxAsync<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>, CancellationToken) MaxAsync<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>, CancellationToken) 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.

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

Asynchronously returns the minimum value of a sequence.

MinAsync<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>, CancellationToken) MinAsync<TSource,TResult>(IQueryable<TSource>, Expression<Func<TSource,TResult>>, CancellationToken) 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.

SingleAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>, CancellationToken) SingleAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>, CancellationToken) 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>, CancellationToken) SingleAsync<TSource>(IQueryable<TSource>, CancellationToken) 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.

SingleOrDefaultAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>, CancellationToken) SingleOrDefaultAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>, CancellationToken) 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>, CancellationToken) SingleOrDefaultAsync<TSource>(IQueryable<TSource>, CancellationToken) 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.

SumAsync(IQueryable<Decimal>, CancellationToken) SumAsync(IQueryable<Decimal>, CancellationToken) SumAsync(IQueryable<Decimal>, CancellationToken)

Asynchronously computes the sum of a sequence of values.

SumAsync(IQueryable<Double>, CancellationToken) SumAsync(IQueryable<Double>, CancellationToken) SumAsync(IQueryable<Double>, CancellationToken)

Asynchronously computes the sum of a sequence of values.

SumAsync(IQueryable<Int32>, CancellationToken) SumAsync(IQueryable<Int32>, CancellationToken) SumAsync(IQueryable<Int32>, CancellationToken)

Asynchronously computes the sum of a sequence of values.

SumAsync(IQueryable<Int64>, CancellationToken) SumAsync(IQueryable<Int64>, CancellationToken) SumAsync(IQueryable<Int64>, CancellationToken)

Asynchronously computes the sum of a sequence of values.

SumAsync(IQueryable<Nullable<Decimal>>, CancellationToken) SumAsync(IQueryable<Nullable<Decimal>>, CancellationToken) SumAsync(IQueryable<Nullable<Decimal>>, CancellationToken)

Asynchronously computes the sum of a sequence of values.

SumAsync(IQueryable<Nullable<Double>>, CancellationToken) SumAsync(IQueryable<Nullable<Double>>, CancellationToken) SumAsync(IQueryable<Nullable<Double>>, CancellationToken)

Asynchronously computes the sum of a sequence of values.

SumAsync(IQueryable<Nullable<Int32>>, CancellationToken) SumAsync(IQueryable<Nullable<Int32>>, CancellationToken) SumAsync(IQueryable<Nullable<Int32>>, CancellationToken)

Asynchronously computes the sum of a sequence of values.

SumAsync(IQueryable<Nullable<Int64>>, CancellationToken) SumAsync(IQueryable<Nullable<Int64>>, CancellationToken) SumAsync(IQueryable<Nullable<Int64>>, CancellationToken)

Asynchronously computes the sum of a sequence of values.

SumAsync(IQueryable<Nullable<Single>>, CancellationToken) SumAsync(IQueryable<Nullable<Single>>, CancellationToken) SumAsync(IQueryable<Nullable<Single>>, CancellationToken)

Asynchronously computes the sum of a sequence of values.

SumAsync(IQueryable<Single>, CancellationToken) SumAsync(IQueryable<Single>, CancellationToken) SumAsync(IQueryable<Single>, CancellationToken)

Asynchronously computes the sum of a sequence of values.

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

Asynchronously computes the sum of the sequence of 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) SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Double>>, CancellationToken) SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Double>>, CancellationToken)

Asynchronously computes the sum of the sequence of 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) SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>, CancellationToken) SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int32>>, CancellationToken)

Asynchronously computes the sum of the sequence of 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) SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int64>>, CancellationToken) SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Int64>>, CancellationToken)

Asynchronously computes the sum of the sequence of 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) SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Decimal>>>, CancellationToken) SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Decimal>>>, CancellationToken)

Asynchronously computes the sum of the sequence of 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) SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Double>>>, CancellationToken) SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Double>>>, CancellationToken)

Asynchronously computes the sum of the sequence of 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) SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Int32>>>, CancellationToken) SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Int32>>>, CancellationToken)

Asynchronously computes the sum of the sequence of 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) SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Int64>>>, CancellationToken) SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Int64>>>, CancellationToken)

Asynchronously computes the sum of the sequence of 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) SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Single>>>, CancellationToken) SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Nullable<Single>>>, CancellationToken)

Asynchronously computes the sum of the sequence of 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) SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Single>>, CancellationToken) SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Single>>, CancellationToken)

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

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

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

ToDictionaryAsync<TSource,TKey>(IQueryable<TSource>, Func<TSource,TKey>, IEqualityComparer<TKey>, CancellationToken) ToDictionaryAsync<TSource,TKey>(IQueryable<TSource>, Func<TSource,TKey>, IEqualityComparer<TKey>, CancellationToken) 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>, CancellationToken) ToDictionaryAsync<TSource,TKey>(IQueryable<TSource>, Func<TSource,TKey>, CancellationToken) 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,TElement>(IQueryable<TSource>, Func<TSource,TKey>, Func<TSource,TElement>, IEqualityComparer<TKey>, CancellationToken) ToDictionaryAsync<TSource,TKey,TElement>(IQueryable<TSource>, Func<TSource,TKey>, Func<TSource,TElement>, IEqualityComparer<TKey>, CancellationToken) 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>, CancellationToken) ToDictionaryAsync<TSource,TKey,TElement>(IQueryable<TSource>, Func<TSource,TKey>, Func<TSource,TElement>, CancellationToken) 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.

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

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

AsAsyncEnumerable<TSource>(IQueryable<TSource>) AsAsyncEnumerable<TSource>(IQueryable<TSource>) AsAsyncEnumerable<TSource>(IQueryable<TSource>)

This API supports the Entity Framework Core infrastructure and is not intended to be used directly from your code. This API may change or be removed in future releases.

Select(IQueryable, String, Type, Type) Select(IQueryable, String, Type, Type) Select(IQueryable, String, Type, Type)

This API supports the Entity Framework Core infrastructure and is not intended to be used directly from your code. This API may change or be removed in future releases.

Select<TSource,TResult>(IQueryable<TSource>, String) Select<TSource,TResult>(IQueryable<TSource>, String) Select<TSource,TResult>(IQueryable<TSource>, String)

This API supports the Entity Framework Core infrastructure and is not intended to be used directly from your code. This API may change or be removed in future releases.

GetInfrastructure<T>(IInfrastructure<T>) GetInfrastructure<T>(IInfrastructure<T>) GetInfrastructure<T>(IInfrastructure<T>)

Gets the value from a property that is being hidden using IInfrastructure<T>.

This method is typically used by database providers (and other extensions). It is generally not used in application code.

IInfrastructure<T> is used to hide properties that are not intended to be used in application code but can be used in extension methods written by database providers etc.

GetService<TService>(IInfrastructure<IServiceProvider>) GetService<TService>(IInfrastructure<IServiceProvider>) GetService<TService>(IInfrastructure<IServiceProvider>)

Resolves a service from the IServiceProvider exposed from a type that implements IInfrastructure<T>.

This method is typically used by database providers (and other extensions). It is generally not used in application code.

IInfrastructure<T> is used to hide properties that are not intended to be used in application code but can be used in extension methods written by database providers etc.

Distinct<T>(IEnumerable<T>, Func<T,T,Boolean>) Distinct<T>(IEnumerable<T>, Func<T,T,Boolean>) Distinct<T>(IEnumerable<T>, Func<T,T,Boolean>)

This API supports the Entity Framework Core infrastructure and is not intended to be used directly from your code. This API may change or be removed in future releases.

FirstOr<T>(IEnumerable<T>, T) FirstOr<T>(IEnumerable<T>, T) FirstOr<T>(IEnumerable<T>, T)

This API supports the Entity Framework Core infrastructure and is not intended to be used directly from your code. This API may change or be removed in future releases.

FirstOr<T>(IEnumerable<T>, Func<T,Boolean>, T) FirstOr<T>(IEnumerable<T>, Func<T,Boolean>, T) FirstOr<T>(IEnumerable<T>, Func<T,Boolean>, T)

This API supports the Entity Framework Core infrastructure and is not intended to be used directly from your code. This API may change or be removed in future releases.

IndexOf<T>(IEnumerable<T>, T) IndexOf<T>(IEnumerable<T>, T) IndexOf<T>(IEnumerable<T>, T)

This API supports the Entity Framework Core infrastructure and is not intended to be used directly from your code. This API may change or be removed in future releases.

IndexOf<T>(IEnumerable<T>, T, IEqualityComparer<T>) IndexOf<T>(IEnumerable<T>, T, IEqualityComparer<T>) IndexOf<T>(IEnumerable<T>, T, IEqualityComparer<T>)

This API supports the Entity Framework Core infrastructure and is not intended to be used directly from your code. This API may change or be removed in future releases.

Join(IEnumerable<Object>, String) Join(IEnumerable<Object>, String) Join(IEnumerable<Object>, String)

This API supports the Entity Framework Core infrastructure and is not intended to be used directly from your code. This API may change or be removed in future releases.

OrderByOrdinal<TSource>(IEnumerable<TSource>, Func<TSource,String>) OrderByOrdinal<TSource>(IEnumerable<TSource>, Func<TSource,String>) OrderByOrdinal<TSource>(IEnumerable<TSource>, Func<TSource,String>)

This API supports the Entity Framework Core infrastructure and is not intended to be used directly from your code. This API may change or be removed in future releases.

StartsWith<TSource>(IEnumerable<TSource>, IEnumerable<TSource>) StartsWith<TSource>(IEnumerable<TSource>, IEnumerable<TSource>) StartsWith<TSource>(IEnumerable<TSource>, IEnumerable<TSource>)

This API supports the Entity Framework Core infrastructure and is not intended to be used directly from your code. This API may change or be removed in future releases.

StructuralSequenceEqual<TSource>(IEnumerable<TSource>, IEnumerable<TSource>) StructuralSequenceEqual<TSource>(IEnumerable<TSource>, IEnumerable<TSource>) StructuralSequenceEqual<TSource>(IEnumerable<TSource>, IEnumerable<TSource>)

This API supports the Entity Framework Core infrastructure and is not intended to be used directly from your code. This API may change or be removed in future releases.

FormatColumns(IEnumerable<IProperty>) FormatColumns(IEnumerable<IProperty>) FormatColumns(IEnumerable<IProperty>)

This API supports the Entity Framework Core infrastructure and is not intended to be used directly from your code. This API may change or be removed in future releases.

AsConcreteMetadataType<TInterface,TConcrete>(TInterface, String) AsConcreteMetadataType<TInterface,TConcrete>(TInterface, String) AsConcreteMetadataType<TInterface,TConcrete>(TInterface, String)

This API supports the Entity Framework Core infrastructure and is not intended to be used directly from your code. This API may change or be removed in future releases.

CreateProxy<TEntity>(DbSet<TEntity>, Object[]) CreateProxy<TEntity>(DbSet<TEntity>, Object[]) CreateProxy<TEntity>(DbSet<TEntity>, Object[])

Creates a proxy instance for an entity type if proxy creation has been turned on.

FromSql<TEntity>(IQueryable<TEntity>, RawSqlString, Object[]) FromSql<TEntity>(IQueryable<TEntity>, RawSqlString, Object[]) FromSql<TEntity>(IQueryable<TEntity>, RawSqlString, Object[])

Creates a LINQ query based on a raw SQL query.

If the database provider supports composing on the supplied SQL, you can compose on top of the raw SQL query using LINQ operators -

context.Blogs.FromSql("SELECT * FROM dbo.Blogs").OrderBy(b => b.Name)
.

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.Blogs.FromSql("SELECT * FROM [dbo].[SearchBlogs]({0})", userSuppliedSearchTerm)
.

This overload also accepts DbParameter instances as parameter values. This allows you to use named parameters in the SQL query string -

context.Blogs.FromSql("SELECT * FROM [dbo].[SearchBlogs]({@searchTerm})", new SqlParameter("@searchTerm", userSuppliedSearchTerm))

FromSql<TEntity>(IQueryable<TEntity>, FormattableString) FromSql<TEntity>(IQueryable<TEntity>, FormattableString) FromSql<TEntity>(IQueryable<TEntity>, FormattableString)

Creates a LINQ query based on an interpolated string representing a SQL query.

If the database provider supports composing on the supplied SQL, you can compose on top of the raw SQL query using LINQ operators -

context.Blogs.FromSql("SELECT * FROM dbo.Blogs").OrderBy(b => b.Name)
.

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 interpolated parameter place holders in the SQL query string. Any interpolated parameter values you supply will automatically be converted to a DbParameter -

context.Blogs.FromSql($"SELECT * FROM [dbo].[SearchBlogs]({userSuppliedSearchTerm})")
.

FromSql<TEntity>(IQueryable<TEntity>, String, Object[]) FromSql<TEntity>(IQueryable<TEntity>, String, Object[]) FromSql<TEntity>(IQueryable<TEntity>, String, Object[])

Creates a LINQ query based on a raw SQL query.

If the database provider supports composing on the supplied SQL, you can compose on top of the raw SQL query using LINQ operators -

context.Blogs.FromSql("SELECT * FROM dbo.Blogs").OrderBy(b => b.Name)
.

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.Blogs.FromSql("SELECT * FROM [dbo].[SearchBlogs]({0})", userSuppliedSearchTerm)
.

You can also construct a DbParameter and supply it to as a parameter value. This allows you to use named parameters in the SQL query string -

context.Blogs.FromSql("SELECT * FROM [dbo].[SearchBlogs]({@searchTerm})", new SqlParameter("@searchTerm", userSuppliedSearchTerm))

Applies to