Set ConnectionString at runtime with DynamicData

Posted by Andrea on 2008-06-16 11:20
Edit the file Global.asax, modify the RegisterRoutes(RouteCollection routes) method.
Instead of the following statement:

model.RegisterContext(typeof(XYZDataContext), new ContextConfiguration() { ScaffoldAllTables = true });

Use

model.RegisterContext
(
  () => new XYZDataContext(connectionString),
  new ContextConfiguration() { ScaffoldAllTables = true }
);

Where connectionString is your string value.
Please note that you can customize the RegisterRoutes's parameter collection,
without comprimosing the application functionality.