Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在提交之前从事务中获取SQL_C#_Sql Server_Database_Transactions - Fatal编程技术网

C# 在提交之前从事务中获取SQL

C# 在提交之前从事务中获取SQL,c#,sql-server,database,transactions,C#,Sql Server,Database,Transactions,我正在用C#开发一个带有SQL Server数据库的项目 当查询具有任何条件时,我希望在数据库中保存一些信息,因此我的想法是使用一个通用方法启动事务的提交,如果提交具有所需的条件,则保存信息 我的问题:有没有办法在.commit()之前获取事务的SQL代码 例如,类似这样的情况: public void insertInfo(object) { using (Context context = new Context()) { [Do an insert]

我正在用C#开发一个带有SQL Server数据库的项目

当查询具有任何条件时,我希望在数据库中保存一些信息,因此我的想法是使用一个通用方法启动事务的提交,如果提交具有所需的条件,则保存信息

我的问题:有没有办法在
.commit()
之前获取事务的SQL代码

例如,类似这样的情况:

public void insertInfo(object)
{
     using (Context context = new Context())
     {
         [Do an insert]
         [Do a second insert]
         [Do an update]     

         context.Save()
     }
} 

// In the Context
public void Save()
{
    [Here I want to get the SQL statement(s) that will be affected by the "transaction.Commit()"]
   transaction.Commit();
}

否没有获取事务当前代码的内置命令或函数


您可以通过创建一个字符串变量自己构建它,每次在函数中执行命令时,都将其添加到变量中,然后在提交事务时读取该变量。

否没有获取事务当前代码的内置命令或函数

您可以通过创建一个字符串变量自己构建它,每次在函数中执行命令时,都将其添加到变量中,然后在提交事务时读取变量