CosmosQueryableExtensions.FromSqlRaw<TEntity> Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Creates a LINQ query based on a raw SQL query.
You can compose on top of the raw SQL query using LINQ operators:
context.Blogs.FromSqlRaw("SELECT * FROM root c).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 Cosmos parameter:
context.Blogs.FromSqlRaw(""SELECT * FROM root c WHERE c["Name"] = {0})", userSuppliedSearchTerm)
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
See Querying data with EF Core, and Accessing Azure Cosmos DB with EF Core for more information.
Applies to
Feedback
Submit and view feedback for