您的位置:首页 > 编程语言 > Qt开发

LinqToEntitiesDomainService Dynamic Binding DataBase ,Silverlight RIA 动态绑定数据库

2011-02-17 15:01 423 查看
手上有个搜索引擎的项目,每个行业都有一个独立的数据库,这些数据库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);
}


[/code]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: