I am new to the repository pattern but am creating a repository to connect to two different database types that have the same data structure. Where and how should I handle the connection?
Here are my requirements/constraints/project description
- I will be connecting to SQL Server 2005 and DB2 (on Iseries)
- I will be using the repository in a WPF application.
- Although I would like to use Entity Framework, I cannot. This is because IBM charges a rediculous $11,000 for a product called DB2 Connect which will then give me access to their Datacontext. Because of budgetary constraints, I will be using ADO.Net instead and the IDBConnection interface.
- The reason why I'm using two different databases is 1) political, 2) because our ERP system is AS400 based which is very limiting so I need to download my data to SQL Server and 3) political.
All of the tutorials I've found discuss opening the connection inside the call to the GetRecords() method. However, that seems to limit me to one database.
So, should I pass in my connection object to my GetRecords method?: GetRecords(MyIDbConnection)? This seems to limit me if I decide to use XML (for whatever reason.)
Inside my GetRecords method, should I make a call to App.Config to get the connection string? Will this limit me if this repository is compiled into a .dll that doesn't have an app.config?
Should I pass in the connection through the constructor instead?
Could I use a data adapter somehow?
Please advise.
Thank You.