4

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:

  1. How to get provider name from connection string? Do we have ConnectionStringSettings for .net core 2.0
  2. 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;
            }
        }
    }
    
9
  • Did you try searching for System.Data.Common in NuGet? Version 4.3.0 should work for .NET Core 2 Commented Jan 29, 2018 at 12:43
  • @Camilo Terevinto, version 4.3.0 (the latest) is installed to my project but I still can't reference DbProviderFactories Commented Jan 29, 2018 at 12:45
  • What's the error message? Because it does exist: github.com/dotnet/corefx/blob/master/src/System.Data.Common/src/… Commented Jan 29, 2018 at 12:47
  • @Camilo Terevinto, unfortunately it doesn't. I'm looking for DbProviderFactories and the reference kindly provided by you is to DbProviderFactory. This is the abstract class and I need somehow to get its instance. Earlier I did it this way DbProviderFactories.GetFactory(settings.ProviderName); Commented Jan 29, 2018 at 12:52
  • Sorry, my bad, but it still exists: github.com/dotnet/corefx/blob/master/src/System.Data.Common/src/… Commented Jan 29, 2018 at 12:53

1 Answer 1

7

DbProviderFactories will be available in .net core 2.1 (2Q 2018).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.