Share via


RelationalQueryableExtensions.FromSqlInterpolated<TEntity> Method

Definition

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

public static System.Linq.IQueryable<TEntity> FromSqlInterpolated<TEntity> (this Microsoft.EntityFrameworkCore.DbSet<TEntity> source, FormattableString sql) where TEntity : class;
static member FromSqlInterpolated : Microsoft.EntityFrameworkCore.DbSet<'Entity (requires 'Entity : null)> * FormattableString -> System.Linq.IQueryable<'Entity (requires 'Entity : null)> (requires 'Entity : null)
<Extension()>
Public Function FromSqlInterpolated(Of TEntity As Class) (source As DbSet(Of TEntity), sql As FormattableString) As IQueryable(Of TEntity)

Type Parameters

TEntity

The type of the elements of source.

Parameters

source
DbSet<TEntity>

An IQueryable<T> to use as the base of the interpolated string SQL query (typically a DbSet<TEntity>).

sql
FormattableString

The interpolated string representing a SQL query with parameters.

Returns

IQueryable<TEntity>

An IQueryable<T> representing the interpolated string SQL query.

Remarks

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

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.

See Executing raw SQL commands with EF Core for more information and examples.

Applies to