c# - Database Factory pattern with multiple databases -


I am creating a database factory pattern for an application that should be able to work with SqlServer and Oracle. I have used the same approach suggested in the following article:

Now, the problem is that my application communicates with multiple databases on the same server for pre: I am running some queries against database DB1 and few questions are being run against DB2, both SQL Server, using the above article, I can make an example of a database I have multiple data Using the same approach to dealing with the press, how can you possibly do? Can somebody help me with this? Thank you.

I recommend that you take a look at the repository pattern. With the use of a repository pattern, you can separate your application from the basic features. This allows you to communicate with one or more databases, web services, file systems or any other data source that is outside of your domain and the application direct control. With it you can make a basic structure that can communicate with many data sources behind the scenes. One example of this was an ecommerce application that I recently worked, on which I was allowed to talk directly to my local database for the product list, but also with SAP behind the scenes for new orders / purchases had spoken.

You may have a code that calls in the repository that looks like this:

  account conservatory _repository = new accountRepository (); Account Account = _repository.GetAccountByID (32);  

Or you could say something to the following:

  account account = new account regressor (). GetAccountByID (32);  

The basic idea behind a repository is that your app can call to obtain the data that it requires, it will return the actual domain objects (like in the example above An account) or it is IEnumerable & lt; Account & gt; can return if a list of accounts is required.

An implementation of this where you can get data from two data sources (although I do not suggest co-relations like this):

  public class Account Reservatory {Public Account GetAccountByID (Intit Account ID) {Account Result = Zero; (MyDataContext DC = New Connection Fitter. GateConnation (Database .db1)) using {Results = DC. ACC Where (A = & gt; ACCID == account ID). FirstOrDefault (); } // The result is zero ... go to another database to get an account (if the result == empty) {(MyDataContext DC = New connectionfine.GetConnation (Database.DB2)) {Results = DC ACC A = & gt; A.AccountID == Account ID) .FirstOrDefault (); }} Return result; }}  

For such a situation, an application service level must be prepared to create my priority, such as application launcher. A repository should be technically related to a data source. Then you can place a few different stores for two different data sources. In your application layer, then the example of GetAccountByID from the repository 1 (database 1), and if it was empty ... then the application layer would then dip into another repository (for example databases 2). If possible, the repository should follow concrete principles where my example clearly breaks solid perspectives, there are more than one reason to change the gateactivitybid!

But ... if this is what you need ... there is a way to do this!


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -