Skip to content

Commit d9ffd09

Browse files
committed
Fixes FransBouma#99 - Resolved KeyValues method by creating a new dictionary of
the returned results.
1 parent 9ab360a commit d9ffd09

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

Massive.Oracle.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public DynamicModel(string connectionStringName, string tableName = "",
118118
string primaryKeyField = "", string descriptorField = "", string sequence = "") {
119119
TableName = tableName == "" ? this.GetType().Name : tableName;
120120
PrimaryKeyField = string.IsNullOrEmpty(primaryKeyField) ? "ID" : primaryKeyField;
121-
121+
DescriptorField = descriptorField;
122122
_sequence = sequence == "" ? ConfigurationManager.AppSettings["default_seq"] : sequence;
123123
_factory = DbProviderFactories.GetFactory("System.Data.OracleClient");
124124
if (ConfigurationManager.ConnectionStrings[connectionStringName] == null)
@@ -177,12 +177,7 @@ public dynamic Prototype {
177177
return result;
178178
}
179179
}
180-
private string _descriptorField;
181-
public string DescriptorField {
182-
get {
183-
return _descriptorField;
184-
}
185-
}
180+
public string DescriptorField { get; protected set; }
186181
/// <summary>
187182
/// List out all the schema bits for use with ... whatever
188183
/// </summary>
@@ -369,7 +364,9 @@ public virtual IDictionary<string, object> KeyValues(string orderBy = "") {
369364
var sql = string.Format("SELECT {0},{1} FROM {2} ", PrimaryKeyField, DescriptorField, TableName);
370365
if (!String.IsNullOrEmpty(orderBy))
371366
sql += "ORDER BY " + orderBy;
372-
return (IDictionary<string, object>)Query(sql);
367+
368+
var results = Query(sql).ToList().Cast<IDictionary<string, object>>()
369+
return results.ToDictionary(key => key[PrimaryKeyField].ToString(), value => value[DescriptorField]);
373370
}
374371

375372
/// <summary>

Massive.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ public DynamicModel(string connectionStringName, string tableName = "",
117117
string primaryKeyField = "", string descriptorField = "") {
118118
TableName = tableName == "" ? this.GetType().Name : tableName;
119119
PrimaryKeyField = string.IsNullOrEmpty(primaryKeyField) ? "ID" : primaryKeyField;
120+
DescriptorField = descriptorField;
120121
var _providerName = "System.Data.SqlClient";
121122
_factory = DbProviderFactories.GetFactory(_providerName);
122123
ConnectionString = ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString;
@@ -172,12 +173,7 @@ public dynamic Prototype {
172173
return result;
173174
}
174175
}
175-
private string _descriptorField = null;
176-
public string DescriptorField {
177-
get {
178-
return _descriptorField;
179-
}
180-
}
176+
public string DescriptorField { get; protected set; }
181177
/// <summary>
182178
/// List out all the schema bits for use with ... whatever
183179
/// </summary>
@@ -363,7 +359,9 @@ public virtual IDictionary<string, object> KeyValues(string orderBy = "") {
363359
var sql = string.Format("SELECT {0},{1} FROM {2} ", PrimaryKeyField, DescriptorField, TableName);
364360
if (!String.IsNullOrEmpty(orderBy))
365361
sql += "ORDER BY " + orderBy;
366-
return (IDictionary<string, object>)Query(sql);
362+
363+
var results = Query(sql).ToList().Cast<IDictionary<string, object>>();
364+
return results.ToDictionary(key => key[PrimaryKeyField].ToString(), value => value[DescriptorField]);
367365
}
368366

369367
/// <summary>

0 commit comments

Comments
 (0)