public static DbContextOptions <T> CreateOptions <T>(DbContext dbContext) where T : DbContext { var serviceProvider = (IInfrastructure <IServiceProvider>)dbContext; #pragma warning disable EF1001 DbContextOptions options = (DbContextOptions)serviceProvider.GetService <IDbContextServices>().ContextOptions; #pragma warning restore EF1001 return((DbContextOptions <T>)options.CreateOptions(typeof(T))); }