【问题标题】:subsonic in visual studio design host视觉工作室设计主机中的亚音速
【发布时间】:2010-11-06 22:31:34
【问题描述】:

我目前面临关于 Subsonic 配置的问题。

我想要实现的是在 System.Web.UI.Design.ControlDesigner 类中使用亚音速数据访问。

此类托管在 Visual Studio 环境中,并在附加的 System.Web.UI.WebControls.Control 上启用设计时操作。

唯一的问题是 SubSonic 似乎总是在应用程序配置中寻找 SubSonicSection,无论是否将连接字符串传递给它。

相关代码sn-p:

using (SharedDbConnectionScope dbScope = new SharedDbConnectionScope(new SqlDataProvider(), ConnectionString))
{
Table1 _table1 = new Select().From<..().Where(...).IsEqualTo(...).ExecuteSingle<...>();

ExecuteSingle() 方法抛出异常(未找到配置部分)

同时

using (SharedDbConnectionScope dbScope = new SharedDbConnectionScope(ConnectionString))
{

在新的 SharedDbConnectionScope() 上抛出异常(未找到配置部分)

所以问题是:
有什么方法可以通过设置运行时绕过配置部分查找,因为我不想将任何亚音速特定配置添加到 devenv.configuration

谢谢

【问题讨论】:

    标签: c# visual-studio subsonic app-config


    【解决方案1】:

    Subsonic runtime provider配置使用方法:

    (示例):

    private void SetSubsonicProviderManually(string ConnectionString)  
    {
    //clear the providers and reset  
    DataService.Provider = new SqlDataProvider();  
    DataService.Providers = new DataProviderCollection();  
    
    //instance a section - we'll set this manually for the DataService  
    SubSonicSection section = new SubSonicSection();  
    section.DefaultProvider = __SubsonicProviderName__;  
    
    //set the properties
    DataProvider provider = DataService.Provider;  
    NameValueCollection config = new NameValueCollection();  
    
    //need to add this for now  
    config.Add("connectionStringName", __ConnectionString__);  
    
    //initialize the provider  
    provider.Initialize(__SubsonicProviderName__, config);  
    
    provider.DefaultConnectionString = ConnectionString;  
    
    DataService.Providers.Add(provider);  
    
    }  
    

    【讨论】:

      【解决方案2】:

      我假设您正在使用基于查询语法的 SubSonic 2.x。看看以下两个论坛帖子,它们应该会为您指明正确的方向。您尝试做的事情是可能的,实际上 SubCommander 正是这样做的,下载源代码并查看 SetProviderManually() 方法。

      http://forums.subsonicproject.com/forums/t/1617.aspx

      http://forums.subsonicproject.com/forums/t/1502.aspx

      【讨论】:

        【解决方案3】:

        如果不自定义模板,我认为您无法在 2.x 中执行此操作(这显然会在发布较新版本的 SubSonic 时出现支持问题)。

        对不起,不知道3.0

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2010-12-03
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-06-11
          相关资源
          最近更新 更多