Permalink
Browse files

Merge pull request #161 from jthope/master

Allow for the usage of a provider supplied in the connection string.
  • Loading branch information...
2 parents 32b0dee + 390c548 commit a20db22d078a6fcf36ddc50c9d997e0af301f6ff @robconery robconery committed Dec 3, 2012
Showing with 18 additions and 8 deletions.
  1. +18 −8 Massive.Oracle.cs
View
@@ -108,23 +108,33 @@ public class DynamicModel : DynamicObject {
string ConnectionString;
string _sequence;
- public static DynamicModel Open(string connectionStringName)
- {
+ public static DynamicModel Open(string connectionStringName) {
dynamic dm = new DynamicModel(connectionStringName);
return dm;
}
public DynamicModel(string connectionStringName, string tableName = "",
string primaryKeyField = "", string descriptorField = "", string sequence = "") {
+
TableName = tableName == "" ? this.GetType().Name : tableName;
PrimaryKeyField = string.IsNullOrEmpty(primaryKeyField) ? "ID" : primaryKeyField;
DescriptorField = descriptorField;
_sequence = sequence == "" ? ConfigurationManager.AppSettings["default_seq"] : sequence;
- _factory = DbProviderFactories.GetFactory("System.Data.OracleClient");
- if (ConfigurationManager.ConnectionStrings[connectionStringName] == null)
+
+ var _providerName = "System.Data.OracleClient";
+ var _connectionStringKey = ConfigurationManager.ConnectionStrings[connectionStringName];
+
+ if (_connectionStringKey == null) {
ConnectionString = connectionStringName;
- else
- ConnectionString = ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString;
+ } else {
+ ConnectionString = _connectionStringKey.ConnectionString;
+ if (!string.IsNullOrEmpty(_connectionStringKey.ProviderName)) {
+ _providerName = _connectionStringKey.ProviderName;
+ }
+ }
+
+ _factory = DbProviderFactories.GetFactory(_providerName);
+
}
/// <summary>
@@ -247,9 +257,9 @@ public static DynamicModel Open(string connectionStringName)
var commands = new List<DbCommand>();
foreach (var item in things) {
if (HasPrimaryKey(item)) {
- commands.Add(CreateUpdateCommand(item, GetPrimaryKey(item)));
+ commands.Add(CreateUpdateCommand(item.ToExpando(), GetPrimaryKey(item)));
} else {
- commands.Add(CreateInsertCommand(item));
+ commands.Add(CreateInsertCommand(item.ToExpando()));
}
}
return commands;

0 comments on commit a20db22

Please sign in to comment.