Last active
June 9, 2017 09:27
-
-
Save webgio/5383f259c38436a4247c71e9c92d1e76 to your computer and use it in GitHub Desktop.
run with dapper (and NHibernate session and ransaction)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void RunInSql(Action<IDbConnection, IDbTransaction> action) | |
{ | |
using (var connection = session.Connection) | |
{ | |
using (var transaction = GetTransaction(session)) | |
{ | |
try | |
{ | |
action(connection, transaction); | |
transaction.Commit(); | |
} | |
catch (Exception ex) | |
{ | |
transaction.Rollback(); | |
throw; | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DapperRun.RunInSql((conn, trans) => { | |
var id = conn.ExecuteScalar<int>("select top 1 new_id from mytable", trans); | |
conn.ExecuteScalar("insert into mytable", trans); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment