How to get connectionString from EF Core 2.0 DbContext

Viewed 23701

In EF6 works this code:

    public string GetConnectionString(DbContext ctx)
    {
        ObjectContext _objectContext = ((IObjectContextAdapter)ctx).ObjectContext;
        if (_objectContext?.Connection != null)
        {
            EntityConnection entityConnection = _objectContext.Connection as EntityConnection;
            return entityConnection?.StoreConnection?.ConnectionString;
        }
        return null;
    }

How to do it in EF Core 2.0 ?

1 Answers
Related