RelationalQueryableExtensions Class

Definition

Relational database specific extension methods for LINQ queries.

public static class RelationalQueryableExtensions
type RelationalQueryableExtensions = class
Public Module RelationalQueryableExtensions
Inheritance
RelationalQueryableExtensions

Methods

AsSingleQuery<TEntity>(IQueryable<TEntity>)

Returns a new query which is configured to load the collections in the query results in a single database query.

AsSplitQuery<TEntity>(IQueryable<TEntity>)

Returns a new query which is configured to load the collections in the query results through separate database queries.

CreateDbCommand(IQueryable)

Creates a DbCommand set up to execute this query.

ExecuteDelete<TSource>(IQueryable<TSource>)

Deletes all database rows for the entity instances which match the LINQ query from the database.

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

Asynchronously deletes database rows for the entity instances which match the LINQ query from the database.

ExecuteUpdate<TSource>(IQueryable<TSource>, Expression<Func<SetPropertyCalls<TSource>,SetPropertyCalls<TSource>>>)

Updates all database rows for the entity instances which match the LINQ query from the database.

ExecuteUpdateAsync<TSource>(IQueryable<TSource>, Expression<Func<SetPropertyCalls<TSource>,SetPropertyCalls<TSource>>>, CancellationToken)

Asynchronously updates database rows for the entity instances which match the LINQ query from the database.

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

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

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

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>, RawSqlString, Object[])
Obsolete.

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>, 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))

FromSqlInterpolated<TEntity>(DbSet<TEntity>, FormattableString)

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

FromSqlRaw<TEntity>(DbSet<TEntity>, String, Object[])

Creates a LINQ query based on a raw SQL query.

Applies to