-
Notifications
You must be signed in to change notification settings - Fork 302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple ADO Providers found specify provider name or remove unwanted assemblies #402
Comments
You have it all wrong. In inversion of control, the Domain have repository interfaces. This DAL (Data Access Layer) depends on the Domain repository interface definition. You then use Dependency Injection to Select the DAL, the implementation can be all different for different database. Of course we can assume implementation is close to same so you can have DAL.Base where you put all common code LINQ queries etc. but in your project you should have something like
Now 1 to be referenced by 2,3,4. and (1), 2, 3, 4 should have reference to 5. to have interface definitions form Domain. Dal.X will implement the interface. DI will inject implemntation of selected Dal to Domain. |
Thanks for the reply, and I appreciate your advise on IOC. The problem though is if I change the code to follow IOC principles in order to separate out MSSQL Provider from MySQL Provider, it throws the following exception:
The issue is, the Root Desktop or Web Application that is referencing the isolated DLL requires a reference to the ADO assembly and Simple.Data core DLLs and won't work unless there is a concrete reference to it. I have even tried to change the Build folder for the Dal.Sql and Dal.MySql libraries, but even if the two DLLs exist in the same bin folder, regardless of if the parent application references them or not it still throws the same exception:
So it seems it doesn't matter how much you abstract the DALs, the two ADO DLLs (Simple.Data.SqlServer.dll and Simple.Data.MySQL.dll) just do not like to co-exist. This brings me back to my original question: Is there a way to specify the Provider Name at Runtime on the Database Object? Thanks, P.S. I have had no such problems when using Dapper. You can see a sample test project here: Ideally if I am able to I would like to get Simple Data working the same way, because it's a lot leaner than Dapper and doesn't require a SQL Query to be specified which is a huge plus. |
I have an asp.net mvc project which uses 3 different database types depending on which one the user select (MSSQL, MySQL & Oracle). The project follows an Adapter/Repository pattern for it's code. You can see the source code here if it helps:
https://sourceforge.net/p/digioznetportal/codenew/ci/master/tree/Source/3.0.0.0/digioz.Portal/
The problem is in order for me to use both MSSQL and MySQL I have added a reference to both those nugets. But now when trying to get data, the Database.OpenConnection method throws this exception:
How can I specify a specific ADO Provider at runtime? I didn't find any methods or constructors on the Database Object itself.
The code in question:
`
public class MySQLData : IDataContext
{
private string connectionString;
private Database Database;
`
Thanks,
Pete
The text was updated successfully, but these errors were encountered: