Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed up a bit of a mess with QueryAsync - explicitly closing off the…

… connection. Set Single to use FirstOrDefault for both implementations
  • Loading branch information...
commit 04ccbaa8ce1f981b5de4dfba704763ee260e64f9 1 parent c5a5a96
@subsonic subsonic authored
Showing with 5 additions and 3 deletions.
  1. +5 −3 Massive.cs
View
8 Massive.cs
@@ -128,11 +128,13 @@ public class DynamicModel : DynamicObject {
/// </summary>
public void QueryAsync(string sql, Action<List<dynamic>> callback, params object[] args) {
using (var conn = new SqlConnection(ConnectionString)) {
- var cmd = new SqlCommand(sql, new SqlConnection(ConnectionString));
+ var cmd = new SqlCommand(sql, conn);
cmd.AddParams(args);
- cmd.Connection.Open();
+ conn.Open();
var task = Task.Factory.FromAsync<IDataReader>(cmd.BeginExecuteReader, cmd.EndExecuteReader, null);
task.ContinueWith(x => callback.Invoke(x.Result.ToExpandoList()));
+ //make sure this is closed off.
+ conn.Close();
}
}
@@ -390,7 +392,7 @@ public class DynamicModel : DynamicObject {
/// </summary>
public virtual dynamic Single(string where, params object[] args) {
var sql = string.Format("SELECT * FROM {0} WHERE {1}", TableName, where);
- return Query(sql, args).First();
+ return Query(sql, args).FirstOrDefault();
}
/// <summary>
/// Returns a single row from the database
Please sign in to comment.
Something went wrong with that request. Please try again.