简体   繁体   English

具有EF的多个SQL数据库-设计的好坏?

[英]Multiple SQL Databases with EF - Good or Bad design?

Currently we have a large in house platform that makes use of a number of different SQL databases (all on the same server). 当前,我们有一个大型的内部平台,该平台使用许多不同的SQL数据库(都在同一服务器上)。 We have always created new databases where we feel that the data is quite different/independant from what we are storing in the other databases. 我们一直在创建新的数据库,在这些数据库中我们认为数据与其他数据库中存储的数据完全不同/独立。 With this approach we have ended up having a number of different databases (most have 30-50+ tables), but inevitably there is always some connections required between them. 通过这种方法,我们最终得到了许多不同的数据库(大多数都有30-50个以上的表),但是不可避免地,它们之间总是需要一些连接。

As we are using Entity Framework, any cross database queries are proving a real pain, we have tried a number of different approaches and I personally feel that the main problem is that EF just doesn't really work across multiple databases. 当我们使用Entity Framework时,任何跨数据库查询都被证明是一个真正的难题,我们尝试了许多不同的方法,而且我个人认为主要问题是EF不能真正跨多个数据库工作。

While I know that the answer is often "it depends" I'm interested in peoples ideas or views on this so really the question is 虽然我知道答案通常是“取决于”的,但我对人们对此的想法或观点很感兴趣,所以实际上问题是

  1. Should we combine all of our seperate databases into one large database? 我们是否应该将所有单独的数据库合并为一个大型数据库?

  2. Were correct to have split our data into different databases (even if EF doesn't work well with it)? 将我们的数据拆分到不同的数据库中是否正确(即使EF无法很好地与之配合使用)?

You say 你说

where we feel that the data is quite different/independant from what we are storing in the other databases 我们认为数据与我们存储在其他数据库中的数据完全不同/无关

and then 接着

cross database queries are proving a real pain 跨数据库查询证明是真正的痛苦

If you're having to do many cross-database queries, then it's likely that the data isn't quite as independent as you thought, in which case it might make more sense to merge the databases. 如果您必须执行许多跨数据库查询,那么数据可能并没有您想象的那么独立,在这种情况下,合并数据库可能更有意义。

On the other hand, if your cross-database queries are rare, then it might be ok. 另一方面,如果很少进行跨数据库查询,则可能没有问题。 Without knowing the details of your domain model and what you've got in each database, it's hard to say. 不知道域模型的详细信息以及每个数据库中包含的内容,这很难说。 Examine the cases where you're making these cross-database queries, and look at why you're making them, and how often that happens. 检查进行这些跨数据库查询的情况,并查看为什么进行这些查询以及发生的频率 If it's important or frequent, then consider merging. 如果重要或频繁,请考虑合并。 If it's rare, or not performance-critical, or the hassle of merging the database far outweighs the hassle of writing these few cross-database queries, then it's probably fine. 如果这种情况很少见,或者对性能不是至关重要的,或者合并数据库的麻烦远远超过编写这几个跨数据库查询的麻烦,那么可能就可以了。 Be careful with that last point though - it might be easier to leave the databases separate now , but you may come across something in the future that would be much easier on a merged database. 不过,请注意最后一点- 现在将数据库分开可能更容易,但是将来您可能会遇到一些事情,在合并的数据库上会容易得多。 Have another look at what sorts of data you're storing in these databases and work out a list of all the scenarios where you might need cross-database querying. 再看看您要在这些数据库中存储什么样的数据,并列出可能需要跨数据库查询的所有方案的列表。 Then look at each of those scenarios and decide how likely it is to happen, and how much of a problem it'll cause if you don't merge the database. 然后查看每种情况,并确定发生这种情况的可能性,以及如果不合并数据库将导致多少问题。 That should help you decide whether to merge. 那应该可以帮助您决定是否合并。

If you do decide to merge, do it as soon as you can. 如果您决定合并,请尽快合并。 Every day that passes without that merge is a day where people are writing code that'll have to be refactored when you do get around to merging. 没有合并的每一天都是人们编写代码的日子,当您开始合并时,就必须对其进行重构。 The sooner you do it, the easier it'll be. 做得越早,就越容易。

How large a database are you talking about? 您要谈论的数据库有多大? How many tables / how many GBs? 多少张表/多少GB? What is the type of data that goes in? 输入的数据类型是什么?

The answer as you guessed is most likely "It depends". 您猜到的答案很可能是“取决于”。 But here I'd say no, splitting is probably not a right choice. 但在这里我要说不,拆分可能不是正确的选择。 If you are having to do cross database queries, most likely the data split is not correct. 如果必须进行跨数据库查询,则很可能是数据分割不正确。 It might be better to split across databases in certain scenarios where the data is independent - like transactional and reporting, for example (but of course that requires a data sync from one to the other). 在某些数据独立的场景中,最好在数据库之间进行拆分,例如事务和报告(例如,当然,这需要一个数据与另一个数据同步)。

Have you considered separating the data in same database, but residing on different schema? 您是否考虑过将数据拆分到同一数据库中,但驻留在不同的架构中? That is what is usually done. 那是通常要做的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM