ObjectContext.ExecuteStoreCommand 方法

定义

重载

ExecuteStoreCommand(String, Object[])

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

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

ExecuteStoreCommand(TransactionalBehavior, String, Object[])

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

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

ExecuteStoreCommand(String, Object[])

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

与任何接受 SQL 的 API 一样,必须参数化任何用户输入,以防止 SQL 注入攻击。 可以在 SQL 查询字符串中包含参数位置持有者,然后将参数值作为其他参数提供。 提供的任何参数值将自动转换为 DbParameter。 上下文。ExecuteStoreCommand (“UPDATE dbo.帖子 SET Rating = 5 WHERE Author = @p0“, userSuppliedAuthor) ;或者,还可以构造 DbParameter 并将其提供给 SqlQuery。 这样可以在 SQL 查询字符串中使用命名参数。 上下文。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。 上下文。ExecuteStoreCommand (“UPDATE dbo.帖子 SET Rating = 5 WHERE Author = @p0“, userSuppliedAuthor) ;或者,还可以构造 DbParameter 并将其提供给 SqlQuery。 这样可以在 SQL 查询字符串中使用命名参数。 上下文。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[]

要用于查询的参数值。

返回

受影响的行数。

适用于