【发布时间】:2018-05-09 18:16:52
【问题描述】:
我正在用 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();
}
【问题讨论】:
标签: c# sql-server database transactions