Skip to content
Browse files

Performance improvements

  • Loading branch information...
1 parent c015abc commit ad55e8ebf63c93fc2078aec31c8bd829dc8a91cf @zvolkov committed
Showing with 6 additions and 3 deletions.
  1. +6 −3 Massive.cs
View
9 Massive.cs
@@ -221,7 +221,7 @@ public class DynamicModel : DynamicObject {
/// <summary>
/// Creates a DBCommand that you can use for loving your database.
/// </summary>
- DbCommand CreateCommand(string sql, DbConnection conn, params object[] args) {
+ public DbCommand CreateCommand(string sql, DbConnection conn, params object[] args) {
var result = _factory.CreateCommand();
result.Connection = conn;
result.CommandText = sql;
@@ -267,10 +267,13 @@ public class DynamicModel : DynamicObject {
/// Executes a series of DBCommands in a transaction
/// </summary>
public virtual int Execute(IEnumerable<DbCommand> commands) {
+ var list = commands.ToList();
+ if (list.Count == 0) return 0;
+
var result = 0;
using (var conn = OpenConnection()) {
using (var tx = conn.BeginTransaction()) {
- foreach (var cmd in commands) {
+ foreach (var cmd in list) {
cmd.Connection = conn;
cmd.Transaction = tx;
result += cmd.ExecuteNonQuery();
@@ -669,4 +672,4 @@ private dynamic BuildPagedResult(string sql = "", string primaryKeyField = "", s
return true;
}
}
-}
+}

0 comments on commit ad55e8e

Please sign in to comment.
Something went wrong with that request. Please try again.