问题描述
我使用的亚音速2从一个项目中,我想从指定默认的App.config不同的config文件。我怎么能告诉亚音速使用特定的配置文件?
I'm using SubSonic 2 from within a project and I'd like to specify a different .config file from the default App.config. How can I tell SubSonic to use a specific config file?
推荐答案
看来,你可以通过设置亚音速对象的两个属性做到这一点: DataService.ConfigSection
和 DataProvider.DefaultConnectionString
。一旦这些都设置亚音速不会尝试查找默认应用程序配置文件,它只会使用你给它的细节。
It appears that you can do this by setting two properties of SubSonic objects: DataService.ConfigSection
and DataProvider.DefaultConnectionString
. Once those are set SubSonic won't try to look for the default application configuration file, it'll just use the details you've given it.
例如:
// Part 1: set the config section:
string configPath = Assembly.GetExecutingAssembly().Location + ".config";
ExeConfigurationFileMap execfg = new ExeConfigurationFileMap();
execfg.ExeConfigFilename = configPath;
Configuration configuration = ConfigurationManager.OpenMappedExeConfiguration(execfg, ConfigurationUserLevel.None);
DataService.ConfigSection = (SubSonicSection)configuration.GetSection(ConfigurationSectionName.SUB_SONIC_SERVICE);
// Part 2: set the connection string
string connectionString = configuration.ConnectionStrings.ConnectionStrings["xLocal"].ConnectionString;
DataProvider provider = DataService.Provider;
provider.DefaultConnectionString = connectionString;
这似乎运作良好,但我有时会遇到长时间的延迟二号到最后一行的DataProvider提供商= DataService.Provider;
。我不知道这是做什么,我在这里做什么,或者它是一个大会装载问题。我记录在这里另一个问题这个问题:Call以System.Web.Configuration.ProvidersHelper.InstantiateProviders考虑年龄和年龄(从亚音速)
This appears to work well, however I am sometimes experiencing a long delay on the 2nd to last line DataProvider provider = DataService.Provider;
. I'm not sure if this is to do with what I'm doing here or it's a general assembly-loading problem. I've documented this problem in another question here: Call to System.Web.Configuration.ProvidersHelper.InstantiateProviders taking ages and ages (from SubSonic)
这篇关于我怎么能告诉亚音速2使用不同的config文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!