Permalink
Browse files

Fixed WHERE spacing in Paged method

  • Loading branch information...
1 parent e32c8b2 commit ee4539f4aa069bac1b9cb6e55a9e0c51b305d91f @subsonic subsonic committed Jun 17, 2011
Showing with 7 additions and 7 deletions.
  1. +7 −7 Massive.cs
View
@@ -93,7 +93,7 @@ public class DynamicModel : DynamicObject {
DbProviderFactory _factory;
string _connectionString;
- public DynamicModel(string connectionStringName,string tableName = "", string primaryKeyField = "") {
+ public DynamicModel(string connectionStringName, string tableName = "", string primaryKeyField = "") {
TableName = tableName == "" ? this.GetType().Name : tableName;
PrimaryKeyField = string.IsNullOrEmpty(primaryKeyField) ? "ID" : primaryKeyField;
var _providerName = "System.Data.SqlClient";
@@ -364,7 +364,7 @@ public class DynamicModel : DynamicObject {
if (!string.IsNullOrEmpty(where)) {
if (!where.Trim().StartsWith("where", StringComparison.CurrentCultureIgnoreCase)) {
- where = "WHERE " + where;
+ where = " WHERE " + where;
}
}
var sql = string.Format("SELECT {0} FROM (SELECT ROW_NUMBER() OVER (ORDER BY {2}) AS Row, {0} FROM {3} {4}) AS Paged ", columns, pageSize, orderBy, TableName, where);
@@ -401,7 +401,7 @@ public class DynamicModel : DynamicObject {
var counter = 0;
var info = binder.CallInfo;
// accepting named args only... SKEET!
- if(info.ArgumentNames.Count != args.Length){
+ if (info.ArgumentNames.Count != args.Length) {
throw new InvalidOperationException("Please use named arguments for this type of query - the column name, orderby, columns, etc");
}
@@ -415,7 +415,7 @@ public class DynamicModel : DynamicObject {
//loop the named args - see if we have order, columns and constraints
if (info.ArgumentNames.Count > 0) {
-
+
for (int i = 0; i < args.Length; i++) {
var name = info.ArgumentNames[i].ToLower();
switch (name) {
@@ -426,7 +426,7 @@ public class DynamicModel : DynamicObject {
columns = args[i].ToString();
break;
default:
- constraints.Add(string.Format(" {0} = @{1}",name,counter));
+ constraints.Add(string.Format(" {0} = @{1}", name, counter));
whereArgs.Add(args[i]);
counter++;
break;
@@ -438,15 +438,15 @@ public class DynamicModel : DynamicObject {
where = " WHERE " + string.Join(" AND ", constraints.ToArray());
}
//build the SQL
- string sql = "SELECT TOP 1 "+columns+" FROM " + TableName + where;
+ string sql = "SELECT TOP 1 " + columns + " FROM " + TableName + where;
var justOne = op.StartsWith("First") || op.StartsWith("Last") || op.StartsWith("Get");
//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;
+ sql = "SELECT " + columns + " FROM " + TableName + where;
justOne = false;
}

0 comments on commit ee4539f

Please sign in to comment.