Permalink
Browse files

Fix issue connection-not-close in Single/First/Last/Get

  • Loading branch information...
1 parent 8a514ee commit 263ca413139243f8a3a6411d41c9f64c62393aaf @buunguyen buunguyen committed Jun 11, 2012
Showing with 10 additions and 13 deletions.
  1. +10 −13 Massive.cs
View
23 Massive.cs
@@ -647,25 +647,22 @@ private dynamic BuildPagedResult(string sql = "", string primaryKeyField = "", s
result = Scalar("SELECT AVG(" + columns + ") FROM " + TableName + where, whereArgs.ToArray());
} else {
- //build the SQL
- sql = "SELECT TOP 1 " + columns + " FROM " + TableName + where;
+ //Build the SQL
var justOne = op.StartsWith("First") || op.StartsWith("Last") || op.StartsWith("Get") || op.StartsWith("Single");
+ if (justOne) {
+ sql = "SELECT TOP 1 " + columns + " FROM " + TableName + where;
+ } else {
+ sql = "SELECT " + columns + " FROM " + TableName + where;
+ }
//Be sure to sort by DESC on the PK (PK Sort is the default)
if (op.StartsWith("Last")) {
orderBy = orderBy + " DESC ";
- } else {
- //default to multiple
- sql = "SELECT " + columns + " FROM " + TableName + where;
- }
+ }
- if (justOne) {
- //return a single record
- result = Query(sql + orderBy, whereArgs.ToArray()).FirstOrDefault();
- } else {
- //return lots
- result = Query(sql + orderBy, whereArgs.ToArray());
- }
+ result = justOne
+ ? Query(sql + orderBy, whereArgs.ToArray()).ToArray().FirstOrDefault()
+ : Query(sql + orderBy, whereArgs.ToArray());
}
return true;
}

0 comments on commit 263ca41

Please sign in to comment.