可以在OrmLite中使用explictit事务吗?
例如,在下面的代码中,我想使用在查询中作为参数传递的事务。这可能吗?
public Order QueryOrder(IDbTransaction transaction)
{
var dbFactory = new OrmLiteConnectionFactory(ConfigurationManager.ConnectionStrings["OrmTests2"].ConnectionString, SqlServerOrmLiteDialectProvider.Instance);
using (IDbConnection dbConn = dbFactory.OpenDbConnection())
{
return dbConn.Single<Order>(x => x.CustomerId == 1, [<transaction>]);
}
}
由于
答案 0 :(得分:1)
您可以在OrmLite的主页上找到使用OrmLite's transaction support的信息和示例,您只需要调用db.OpenTransaction()
来启动ADO.NET交易,例如:
using (IDbConnection db = dbFactory.OpenDbConnection())
using (IDbTransaction dbTrans = db.OpenTransaction())
{
var customer = db.Single<Order>(x => x.CustomerId == 1);
dbTrans.Commit();
}