在一个应用程序中使用多个数据库 [英] Using multiple databases within one application

查看:474
本文介绍了在一个应用程序中使用多个数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Web应用程序,用于几组彼此不联系的人.我正在考虑创建单独的数据库,而不是对所有数据库都使用一个数据库.

I have a web application made for several groups of people not connected with each other. Instead of using one database for all of them, I'm thinking about making separate databases.

这将提高查询速度,并使我不必检查用户所属的组.

This will improve the speed of the queries and make me free from checking to what group the user belongs.

但是,由于我使用的是LINQ to SQL,因此我的类已与数据库明确连接,因此我将必须为所有数据库单独创建DataContexts.

But since I'm working with LINQ to SQL, my classes are explicitly connected with the databases, so I will have to make separate DataContexts for all of the databases.

那么我该如何解决这个问题?还是我应该不打扰,只使用一个数据库?

So how can I solve this problem? Or should I just not bother and use one database only?

推荐答案

如果数据库模式相同,则只需更改每个数据库的连接字符串即可.您不一定需要创建其他上下文.

If the database schemas are the same simply changing the connection string for each database would suffice. You don't necessarily need to create different contexts.

您可能还可以通过查看现有的多租户Asp.NET MVC问题的现有答案来解决您的其他问题.堆栈溢出.

Your other problems are probably solved by reviewing the existing answers for multi-tenancy Asp.NET MVC questions already on Stack Overflow.

这篇关于在一个应用程序中使用多个数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆