Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull Request - Issue 99 KeyValues() Method Exception #102

Merged
merged 2 commits into from
Nov 10, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions Massive.Oracle.cs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public DynamicModel(string connectionStringName, string tableName = "",
string primaryKeyField = "", string descriptorField = "", string sequence = "") { string primaryKeyField = "", string descriptorField = "", string sequence = "") {
TableName = tableName == "" ? this.GetType().Name : tableName; TableName = tableName == "" ? this.GetType().Name : tableName;
PrimaryKeyField = string.IsNullOrEmpty(primaryKeyField) ? "ID" : primaryKeyField; PrimaryKeyField = string.IsNullOrEmpty(primaryKeyField) ? "ID" : primaryKeyField;

DescriptorField = descriptorField;
_sequence = sequence == "" ? ConfigurationManager.AppSettings["default_seq"] : sequence; _sequence = sequence == "" ? ConfigurationManager.AppSettings["default_seq"] : sequence;
_factory = DbProviderFactories.GetFactory("System.Data.OracleClient"); _factory = DbProviderFactories.GetFactory("System.Data.OracleClient");
if (ConfigurationManager.ConnectionStrings[connectionStringName] == null) if (ConfigurationManager.ConnectionStrings[connectionStringName] == null)
Expand Down Expand Up @@ -177,12 +177,7 @@ public dynamic Prototype {
return result; return result;
} }
} }
private string _descriptorField; public string DescriptorField { get; protected set; }
public string DescriptorField {
get {
return _descriptorField;
}
}
/// <summary> /// <summary>
/// List out all the schema bits for use with ... whatever /// List out all the schema bits for use with ... whatever
/// </summary> /// </summary>
Expand Down Expand Up @@ -369,7 +364,9 @@ public virtual IDictionary<string, object> KeyValues(string orderBy = "") {
var sql = string.Format("SELECT {0},{1} FROM {2} ", PrimaryKeyField, DescriptorField, TableName); var sql = string.Format("SELECT {0},{1} FROM {2} ", PrimaryKeyField, DescriptorField, TableName);
if (!String.IsNullOrEmpty(orderBy)) if (!String.IsNullOrEmpty(orderBy))
sql += "ORDER BY " + orderBy; sql += "ORDER BY " + orderBy;
return (IDictionary<string, object>)Query(sql);
var results = Query(sql).ToList().Cast<IDictionary<string, object>>();
return results.ToDictionary(key => key[PrimaryKeyField].ToString(), value => value[DescriptorField]);
} }


/// <summary> /// <summary>
Expand Down
12 changes: 5 additions & 7 deletions Massive.cs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public DynamicModel(string connectionStringName, string tableName = "",
string primaryKeyField = "", string descriptorField = "") { string primaryKeyField = "", string descriptorField = "") {
TableName = tableName == "" ? this.GetType().Name : tableName; TableName = tableName == "" ? this.GetType().Name : tableName;
PrimaryKeyField = string.IsNullOrEmpty(primaryKeyField) ? "ID" : primaryKeyField; PrimaryKeyField = string.IsNullOrEmpty(primaryKeyField) ? "ID" : primaryKeyField;
DescriptorField = descriptorField;
var _providerName = "System.Data.SqlClient"; var _providerName = "System.Data.SqlClient";
_factory = DbProviderFactories.GetFactory(_providerName); _factory = DbProviderFactories.GetFactory(_providerName);
ConnectionString = ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString; ConnectionString = ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString;
Expand Down Expand Up @@ -172,12 +173,7 @@ public dynamic Prototype {
return result; return result;
} }
} }
private string _descriptorField = null; public string DescriptorField { get; protected set; }
public string DescriptorField {
get {
return _descriptorField;
}
}
/// <summary> /// <summary>
/// List out all the schema bits for use with ... whatever /// List out all the schema bits for use with ... whatever
/// </summary> /// </summary>
Expand Down Expand Up @@ -363,7 +359,9 @@ public virtual IDictionary<string, object> KeyValues(string orderBy = "") {
var sql = string.Format("SELECT {0},{1} FROM {2} ", PrimaryKeyField, DescriptorField, TableName); var sql = string.Format("SELECT {0},{1} FROM {2} ", PrimaryKeyField, DescriptorField, TableName);
if (!String.IsNullOrEmpty(orderBy)) if (!String.IsNullOrEmpty(orderBy))
sql += "ORDER BY " + orderBy; sql += "ORDER BY " + orderBy;
return (IDictionary<string, object>)Query(sql);
var results = Query(sql).ToList().Cast<IDictionary<string, object>>();
return results.ToDictionary(key => key[PrimaryKeyField].ToString(), value => value[DescriptorField]);
} }


/// <summary> /// <summary>
Expand Down