zoukankan      html  css  js  c++  java
  • LinqToEntitiesDomainService Dynamic Binding DataBase ,Silverlight RIA 动态绑定数据库

    手上有个搜索引擎的项目,每个行业都有一个独立的数据库,这些数据库schemas都是一样。这样RIA就需要根据客户选择的不同行业连接到不同的数据库。解决办法参看 链接

    这个方法不是最理想的,大致代码如下

    在silverlight端

    private void SetCookie(string cookieName, string cookieValue)
    {
     
    DateTime expireDate = DateTime.Now + TimeSpan.FromDays(1);
     
    string newCookie = cookieName + "=" + cookieValue + ";expires=" + expireDate.ToString("R");
     
    HtmlPage.Document.SetProperty("cookie", newCookie);
    }

    在RIA端override
    protected override ProjectEntities CreateObjectContext()
    {
     
    long projectId = -1;
     
    StringBuilder connection;
     
    if (System.Web.HttpContext.Current.Request.Cookies["SelectedProjectId"] != null)
     
    {
        projectId
    = Convert.ToInt64(System.Web.HttpContext.Current.Request.Cookies["SelectedProjectId"].Value);
     
    }
     
    else throw new Exception("Selected Project ID Exception");  // temporary

     
    // Verify this user has access to the DB just in case it's spoofed

     
    // Lookup project ID in my database to get the database name and server name

     
    // Load template connection string found in web.config
     
    // Replace the template holders for SERVER_NAME and DATABASE_NAME with above lookup values

     
    return new ProjectEntities(MyDynamicConnectionString);      
    }

  • 相关阅读:
    importlib
    js给kindeditor添加值
    在kindeditor 获取textarea 中 输入的值
    获取lable选中时触发事件
    Django之ModelForm组件
    KindEditor 和 xss过滤
    from 动态显示select数据
    CBV 验证装饰器的使用
    views获取数据 -- request包含的方法
    django -- 自定义simpletag 和 filter
  • 原文地址:https://www.cnblogs.com/mjgb/p/1956978.html
Copyright © 2011-2022 走看看