Permalink
Browse files

Added a static DefaultDataProvider property (of type IDataProvider) t…

…o the generated DB class. This can be used as an one-stop shop to make SubSonic use a connection string specified at runtime instead of the one specified at template generation time. The overloaded ActiveRecord constructors/methods just dont cut it for this purpose (you basically need to modify all your db access code).
  • Loading branch information...
1 parent d4458d0 commit 83d53dc6caa867bcd88e451c42dd8e065383fc8d unknown committed with robconery Sep 23, 2009
Showing with 9 additions and 2 deletions.
  1. +9 −2 ActiveRecord/Context.tt
@@ -24,6 +24,8 @@ namespace <#=Namespace#>
public IDataProvider DataProvider;
public DbQueryProvider provider;
+ public static IDataProvider DefaultDataProvider { get; set; }
+
public bool TestMode
{
get
@@ -33,8 +35,13 @@ namespace <#=Namespace#>
}
public <#=DatabaseName#>DB()
- {
- DataProvider = ProviderFactory.GetProvider("<#=ConnectionStringName#>");
+ {
+ if (DefaultDataProvider == null) {
+ DataProvider = ProviderFactory.GetProvider("<#=ConnectionStringName#>");
+ }
+ else {
+ DataProvider = DefaultDataProvider;
+ }
Init();
}

0 comments on commit 83d53dc

Please sign in to comment.