语言

ObjectContext.ExecuteStoreCommand 方法

定义

重载

名称 说明
ExecuteStoreCommand(String, Object[])

使用现有连接直接对数据源执行任意命令。 该命令是使用服务器的本机查询语言(如 SQL)指定的。

与接受 SQL 的任何 API 一样,必须参数化任何用户输入以防止 SQL 注入攻击。 可以在 SQL 查询字符串中包含参数位置持有者,然后将参数值作为其他参数提供。 你提供的任何参数值将自动转换为 DbParameter。 context。ExecuteStoreCommand(“UPDATE dbo.文章 SET 分级 = 5 WHERE Author = @p0“, userSuppliedAuthor;或者,还可以构造 DbParameter 并将其提供给 SqlQuery。 这样,就可以在 SQL 查询字符串中使用命名参数。 context。ExecuteStoreCommand(“UPDATE dbo.文章 SET Rating = 5 WHERE Author = @author“, new SqlParameter(”@author“, userSuppliedAuthor)]

ExecuteStoreCommand(TransactionalBehavior, String, Object[])

使用现有连接直接对数据源执行任意命令。 该命令是使用服务器的本机查询语言(如 SQL)指定的。

与接受 SQL 的任何 API 一样,必须参数化任何用户输入以防止 SQL 注入攻击。 可以在 SQL 查询字符串中包含参数位置持有者,然后将参数值作为其他参数提供。 你提供的任何参数值将自动转换为 DbParameter。 context。ExecuteStoreCommand(“UPDATE dbo.文章 SET 分级 = 5 WHERE Author = @p0“, userSuppliedAuthor;或者,还可以构造 DbParameter 并将其提供给 SqlQuery。 这样,就可以在 SQL 查询字符串中使用命名参数。 context。ExecuteStoreCommand(“UPDATE dbo.文章 SET Rating = 5 WHERE Author = @author“, new SqlParameter(”@author“, userSuppliedAuthor)]

ExecuteStoreCommand(String, Object[])

使用现有连接直接对数据源执行任意命令。 该命令是使用服务器的本机查询语言(如 SQL)指定的。

与接受 SQL 的任何 API 一样,必须参数化任何用户输入以防止 SQL 注入攻击。 可以在 SQL 查询字符串中包含参数位置持有者,然后将参数值作为其他参数提供。 你提供的任何参数值将自动转换为 DbParameter。 context。ExecuteStoreCommand(“UPDATE dbo.文章 SET 分级 = 5 WHERE Author = @p0“, userSuppliedAuthor;或者,还可以构造 DbParameter 并将其提供给 SqlQuery。 这样,就可以在 SQL 查询字符串中使用命名参数。 context。ExecuteStoreCommand(“UPDATE dbo.文章 SET Rating = 5 WHERE Author = @author“, new SqlParameter(”@author“, userSuppliedAuthor)]

public virtual int ExecuteStoreCommand(string commandText, params object[] parameters);
abstract member ExecuteStoreCommand : string * obj[] -> int
override this.ExecuteStoreCommand : string * obj[] -> int
Public Overridable Function ExecuteStoreCommand (commandText As String, ParamArray parameters As Object()) As Integer

参数

commandText
String

在服务器的本机查询语言中指定的命令。

parameters
Object[]

要用于查询的参数值。

返回

受影响的行数。

注解

如果没有现有的本地事务,则新事务将用于执行该命令。

适用于

ExecuteStoreCommand(TransactionalBehavior, String, Object[])

使用现有连接直接对数据源执行任意命令。 该命令是使用服务器的本机查询语言(如 SQL)指定的。

与接受 SQL 的任何 API 一样,必须参数化任何用户输入以防止 SQL 注入攻击。 可以在 SQL 查询字符串中包含参数位置持有者,然后将参数值作为其他参数提供。 你提供的任何参数值将自动转换为 DbParameter。 context。ExecuteStoreCommand(“UPDATE dbo.文章 SET 分级 = 5 WHERE Author = @p0“, userSuppliedAuthor;或者,还可以构造 DbParameter 并将其提供给 SqlQuery。 这样,就可以在 SQL 查询字符串中使用命名参数。 context。ExecuteStoreCommand(“UPDATE dbo.文章 SET Rating = 5 WHERE Author = @author“, new SqlParameter(”@author“, userSuppliedAuthor)]

public virtual int ExecuteStoreCommand(System.Data.Entity.TransactionalBehavior transactionalBehavior, string commandText, params object[] parameters);
abstract member ExecuteStoreCommand : System.Data.Entity.TransactionalBehavior * string * obj[] -> int
override this.ExecuteStoreCommand : System.Data.Entity.TransactionalBehavior * string * obj[] -> int

参数

transactionalBehavior
TransactionalBehavior

控制为此命令创建事务。

commandText
String

在服务器的本机查询语言中指定的命令。

parameters
Object[]

要用于查询的参数值。

返回

受影响的行数。

适用于