CosmosQueryableExtensions.FromSqlRaw<TEntity> Method

Definition

Creates a LINQ query based on a raw SQL query.

public static System.Linq.IQueryable<TEntity> FromSqlRaw<TEntity> (this Microsoft.EntityFrameworkCore.DbSet<TEntity> source, string sql, params object[] parameters) where TEntity : class;
static member FromSqlRaw : Microsoft.EntityFrameworkCore.DbSet<'Entity (requires 'Entity : null)> * string * obj[] -> System.Linq.IQueryable<'Entity (requires 'Entity : null)> (requires 'Entity : null)
<Extension()>
Public Function FromSqlRaw(Of TEntity As Class) (source As DbSet(Of TEntity), sql As String, ParamArray parameters As Object()) 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 raw SQL query (typically a DbSet<TEntity>).

sql
String

The raw SQL query.

parameters
Object[]

The values to be assigned to parameters.

Returns

IQueryable<TEntity>

An IQueryable<T> representing the raw SQL query.

Remarks

The returned IQueryable<T> can be composed over using LINQ to build more complex queries.

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 Cosmos parameter.

See Querying data with EF Core, and Accessing Azure Cosmos DB with EF Core for more information and examples.

Applies to