How to get connectionString from EF Core 2.0 DbContext

.net-core entity-framework entity-framework-core

Question

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
26
7/26/2017 9:06:06 AM

Accepted Answer

var connectionString = ctx.Database.GetDbConnection().ConnectionString;
59
7/26/2017 4:19:08 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow