Reputation: 136
Is possible to use an explictit transaction in OrmLite?
For example, in the code below i would like to use the transaction passed as parameter in the query. Is that possible?
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>]);
}
}
Thanks
Upvotes: 0
Views: 434
Reputation: 143284
You can find info and examples of using OrmLite's transaction support on OrmLite's homepage where you'd just need to call db.OpenTransaction()
to start an ADO.NET transaction, e.g:
using (IDbConnection db = dbFactory.OpenDbConnection())
using (IDbTransaction dbTrans = db.OpenTransaction())
{
var customer = db.Single<Order>(x => x.CustomerId == 1);
dbTrans.Commit();
}
Upvotes: 1