语言

RelationalQueryableExtensions.FromSql 方法

定义

重载

名称 说明
FromSql<TEntity>(DbSet<TEntity>, FormattableString)

基于表示 SQL 查询的内插字符串创建 LINQ 查询。

FromSql<TEntity>(IQueryable<TEntity>, FormattableString)
已过时.

基于表示 SQL 查询的内插字符串创建 LINQ 查询。

如果数据库提供程序支持在提供的 SQL 上进行撰写,则可以使用 LINQ 运算符在原始 SQL 查询的基础上进行撰写 - context.Blogs.FromSql("SELECT * FROM dbo.Blogs").OrderBy(b => b.Name)。

与接受 SQL 的任何 API 一样,必须参数化任何用户输入以防止 SQL 注入攻击。 可以在 SQL 查询字符串中包含内插参数位置持有者。 你提供的任何内插参数值将自动转换为 DbParameter - context.Blogs.FromSql($"SELECT * FROM [dbo].[SearchBlogs]({userSuppliedSearchTerm})")。

FromSql<TEntity>(IQueryable<TEntity>, RawSqlString, Object[])
已过时.

基于原始 SQL 查询创建 LINQ 查询。

如果数据库提供程序支持在提供的 SQL 上进行撰写,则可以使用 LINQ 运算符在原始 SQL 查询的基础上进行撰写 - context.Blogs.FromSql("SELECT * FROM dbo.Blogs").OrderBy(b => b.Name)。

与接受 SQL 的任何 API 一样,必须参数化任何用户输入以防止 SQL 注入攻击。 可以在 SQL 查询字符串中包含参数位置持有者,然后将参数值作为其他参数提供。 你提供的任何参数值将自动转换为 DbParameter - context.Blogs.FromSql("SELECT * FROM [dbo].[SearchBlogs]({0})", userSuppliedSearchTerm)。

此重载还接受 DbParameter 实例作为参数值。 这允许在 SQL 查询字符串中使用命名参数 - context.Blogs.FromSql("SELECT * FROM [dbo].[SearchBlogs]({@searchTerm})", new SqlParameter("@searchTerm", userSuppliedSearchTerm))

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

基于原始 SQL 查询创建 LINQ 查询。

如果数据库提供程序支持在提供的 SQL 上进行撰写,则可以使用 LINQ 运算符在原始 SQL 查询的基础上进行撰写 - context.Blogs.FromSql("SELECT * FROM dbo.Blogs").OrderBy(b => b.Name)。

与接受 SQL 的任何 API 一样,必须参数化任何用户输入以防止 SQL 注入攻击。 可以在 SQL 查询字符串中包含参数位置持有者,然后将参数值作为其他参数提供。 你提供的任何参数值将自动转换为 DbParameter - context.Blogs.FromSql("SELECT * FROM [dbo].[SearchBlogs]({0})", userSuppliedSearchTerm)。

还可以构造 DbParameter 并将其作为参数值提供。 这允许在 SQL 查询字符串中使用命名参数 - context.Blogs.FromSql("SELECT * FROM [dbo].[SearchBlogs]({@searchTerm})", new SqlParameter("@searchTerm", userSuppliedSearchTerm))

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

Source:
RelationalQueryableExtensions.cs
Source:
RelationalQueryableExtensions.cs
Source:
RelationalQueryableExtensions.cs
Source:
RelationalQueryableExtensions.cs
Source:
RelationalQueryableExtensions.cs

基于表示 SQL 查询的内插字符串创建 LINQ 查询。

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

类型参数

TEntity

的元素 source的类型。

参数

source
DbSet<TEntity>

IQueryable<T>用作内插字符串 SQL 查询的基数(通常是一个DbSet<TEntity>)。

sql
FormattableString

表示具有参数的 SQL 查询的内插字符串。

返回

IQueryable<TEntity>

表示 IQueryable<T> 内插字符串 SQL 查询。

注解

如果数据库提供程序支持在提供的 SQL 上进行撰写,则可以使用 LINQ 运算符在原始 SQL 查询的基础上进行撰写。

与接受 SQL 的任何 API 一样,必须参数化任何用户输入以防止 SQL 注入攻击。 可以在 SQL 查询字符串中包含内插参数位置持有者。 你提供的任何内插参数值将自动转换为一个 DbParameter。

有关详细信息和示例,请参阅 使用 EF Core 执行原始 SQL 命令 。

适用于

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

Source:
RelationalQueryableExtensions.cs
Source:
RelationalQueryableExtensions.cs
Source:
RelationalQueryableExtensions.cs
Source:
RelationalQueryableExtensions.cs

注意

For returning objects from SQL queries using plain strings, use FromSqlRaw instead. For returning objects from SQL queries using interpolated string syntax to create parameters, use FromSqlInterpolated instead. Call either new method directly on the DbSet at the root of the query.

基于表示 SQL 查询的内插字符串创建 LINQ 查询。

如果数据库提供程序支持在提供的 SQL 上进行撰写,则可以使用 LINQ 运算符在原始 SQL 查询的基础上进行撰写 - context.Blogs.FromSql("SELECT * FROM dbo.Blogs").OrderBy(b => b.Name)。

与接受 SQL 的任何 API 一样,必须参数化任何用户输入以防止 SQL 注入攻击。 可以在 SQL 查询字符串中包含内插参数位置持有者。 你提供的任何内插参数值将自动转换为 DbParameter - context.Blogs.FromSql($"SELECT * FROM [dbo].[SearchBlogs]({userSuppliedSearchTerm})")。

public static System.Linq.IQueryable<TEntity> FromSql<TEntity>(this System.Linq.IQueryable<TEntity> source, FormattableString sql) where TEntity : class;
[System.Obsolete("For returning objects from SQL queries using plain strings, use FromSqlRaw instead. For returning objects from SQL queries using interpolated string syntax to create parameters, use FromSqlInterpolated instead. Call either new method directly on the DbSet at the root of the query.", true)]
public static System.Linq.IQueryable<TEntity> FromSql<TEntity>(this System.Linq.IQueryable<TEntity> source, FormattableString sql) where TEntity : class;
static member FromSql : System.Linq.IQueryable<'Entity (requires 'Entity : null)> * FormattableString -> System.Linq.IQueryable<'Entity (requires 'Entity : null)> (requires 'Entity : null)
[<System.Obsolete("For returning objects from SQL queries using plain strings, use FromSqlRaw instead. For returning objects from SQL queries using interpolated string syntax to create parameters, use FromSqlInterpolated instead. Call either new method directly on the DbSet at the root of the query.", true)>]
static member FromSql : System.Linq.IQueryable<'Entity (requires 'Entity : null)> * FormattableString -> System.Linq.IQueryable<'Entity (requires 'Entity : null)> (requires 'Entity : null)
<Extension()>
Public Function FromSql(Of TEntity As Class) (source As IQueryable(Of TEntity), sql As FormattableString) As IQueryable(Of TEntity)

类型参数

TEntity

的元素 source的类型。

参数

source
IQueryable<TEntity>

IQueryable<T>用作内插字符串 SQL 查询的基数(通常是一个DbSet<TEntity>)。

sql
FormattableString

表示 SQL 查询的内插字符串。

返回

IQueryable<TEntity>

表示 IQueryable<T> 内插字符串 SQL 查询。

特性

适用于

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

Source:
RelationalQueryableExtensions.cs
Source:
RelationalQueryableExtensions.cs
Source:
RelationalQueryableExtensions.cs
Source:
RelationalQueryableExtensions.cs

注意

For returning objects from SQL queries using plain strings, use FromSqlRaw instead. For returning objects from SQL queries using interpolated string syntax to create parameters, use FromSqlInterpolated instead. Call either new method directly on the DbSet at the root of the query.

基于原始 SQL 查询创建 LINQ 查询。

如果数据库提供程序支持在提供的 SQL 上进行撰写,则可以使用 LINQ 运算符在原始 SQL 查询的基础上进行撰写 - context.Blogs.FromSql("SELECT * FROM dbo.Blogs").OrderBy(b => b.Name)。

与接受 SQL 的任何 API 一样,必须参数化任何用户输入以防止 SQL 注入攻击。 可以在 SQL 查询字符串中包含参数位置持有者,然后将参数值作为其他参数提供。 你提供的任何参数值将自动转换为 DbParameter - context.Blogs.FromSql("SELECT * FROM [dbo].[SearchBlogs]({0})", userSuppliedSearchTerm)。

此重载还接受 DbParameter 实例作为参数值。 这允许在 SQL 查询字符串中使用命名参数 - context.Blogs.FromSql("SELECT * FROM [dbo].[SearchBlogs]({@searchTerm})", new SqlParameter("@searchTerm", userSuppliedSearchTerm))

public static System.Linq.IQueryable<TEntity> FromSql<TEntity>(this System.Linq.IQueryable<TEntity> source, Microsoft.EntityFrameworkCore.RawSqlString sql, params object[] parameters) where TEntity : class;
[System.Obsolete("For returning objects from SQL queries using plain strings, use FromSqlRaw instead. For returning objects from SQL queries using interpolated string syntax to create parameters, use FromSqlInterpolated instead. Call either new method directly on the DbSet at the root of the query.", true)]
public static System.Linq.IQueryable<TEntity> FromSql<TEntity>(this System.Linq.IQueryable<TEntity> source, Microsoft.EntityFrameworkCore.RawSqlString sql, params object[] parameters) where TEntity : class;
static member FromSql : System.Linq.IQueryable<'Entity (requires 'Entity : null)> * Microsoft.EntityFrameworkCore.RawSqlString * obj[] -> System.Linq.IQueryable<'Entity (requires 'Entity : null)> (requires 'Entity : null)
[<System.Obsolete("For returning objects from SQL queries using plain strings, use FromSqlRaw instead. For returning objects from SQL queries using interpolated string syntax to create parameters, use FromSqlInterpolated instead. Call either new method directly on the DbSet at the root of the query.", true)>]
static member FromSql : System.Linq.IQueryable<'Entity (requires 'Entity : null)> * Microsoft.EntityFrameworkCore.RawSqlString * obj[] -> System.Linq.IQueryable<'Entity (requires 'Entity : null)> (requires 'Entity : null)
<Extension()>
Public Function FromSql(Of TEntity As Class) (source As IQueryable(Of TEntity), sql As RawSqlString, ParamArray parameters As Object()) As IQueryable(Of TEntity)

类型参数

TEntity

的元素 source的类型。

参数

source
IQueryable<TEntity>

IQueryable<T>用作原始 SQL 查询的基数(通常是一个DbSet<TEntity>)。

sql
RawSqlString

原始 SQL 查询。 NB. 此处可能会传递字符串文本,因为 RawSqlString 可隐式转换为字符串。

parameters
Object[]

要分配给参数的值。

返回

IQueryable<TEntity>

表示 IQueryable<T> 原始 SQL 查询。

特性

适用于

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

基于原始 SQL 查询创建 LINQ 查询。

如果数据库提供程序支持在提供的 SQL 上进行撰写,则可以使用 LINQ 运算符在原始 SQL 查询的基础上进行撰写 - context.Blogs.FromSql("SELECT * FROM dbo.Blogs").OrderBy(b => b.Name)。

与接受 SQL 的任何 API 一样,必须参数化任何用户输入以防止 SQL 注入攻击。 可以在 SQL 查询字符串中包含参数位置持有者,然后将参数值作为其他参数提供。 你提供的任何参数值将自动转换为 DbParameter - context.Blogs.FromSql("SELECT * FROM [dbo].[SearchBlogs]({0})", userSuppliedSearchTerm)。

还可以构造 DbParameter 并将其作为参数值提供。 这允许在 SQL 查询字符串中使用命名参数 - context.Blogs.FromSql("SELECT * FROM [dbo].[SearchBlogs]({@searchTerm})", new SqlParameter("@searchTerm", userSuppliedSearchTerm))

public static System.Linq.IQueryable<TEntity> FromSql<TEntity>(this System.Linq.IQueryable<TEntity> source, string sql, params object[] parameters) where TEntity : class;
static member FromSql : System.Linq.IQueryable<'Entity (requires 'Entity : null)> * string * obj[] -> System.Linq.IQueryable<'Entity (requires 'Entity : null)> (requires 'Entity : null)
<Extension()>
Public Function FromSql(Of TEntity As Class) (source As IQueryable(Of TEntity), sql As String, ParamArray parameters As Object()) As IQueryable(Of TEntity)

类型参数

TEntity

的元素 source的类型。

参数

source
IQueryable<TEntity>

IQueryable<T>用作原始 SQL 查询的基数(通常是一个DbSet<TEntity>)。

sql
String

原始 SQL 查询。

parameters
Object[]

要分配给参数的值。

返回

IQueryable<TEntity>

表示 IQueryable<T> 原始 SQL 查询。

适用于