EF6では、次のコードが機能します。
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;
}
EF Core 2.0でそれを行う方法は?
var connectionString = ctx.Database.GetDbConnection().ConnectionString;