Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed WHERE spacing in Paged method
  • Loading branch information
subsonic committed Jun 17, 2011
1 parent e32c8b2 commit ee4539f
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions Massive.cs
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");
}

Expand All @@ -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) {
Expand All @@ -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;
Expand All @@ -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;
}

Expand Down

0 comments on commit ee4539f

Please sign in to comment.