I'm trying to migrate a small .net framework project to .net core one. But I've spent a couple of hours searching how to adopt the code below to .net core 2.0. But I was unlucky, because it seems that System.Data.Common functionality was cut for some reason. So, I've 2 problems here:
- How to get provider name from connection string? Do we have ConnectionStringSettings for .net core 2.0
How can we get a factory base only on provider name string? Any other thought how to perform loosely coupled db connection factory
public class ConnectionFactory { protected readonly DbProviderFactory Factory; protected readonly string ConnectionString; public ConnectionFactory(string connectionStringName) { var settings = ConfigurationManager.ConnectionStrings[connectionStringName]; this.Factory = DbProviderFactories.GetFactory(settings.ProviderName); this.ConnectionString = settings.ConnectionString; } public DbConnection Connection { get { var con = Factory.CreateConnection(); con.ConnectionString = this.ConnectionString; return con; } } }
System.Data.Commonin NuGet? Version 4.3.0 should work for .NET Core 2