public DbDirectoryAccountService()
        {
#if NET45
            string url = ConfigurationManager.AppSettings["DirectoryAccountService.RootEntryPath"];
            if (String.IsNullOrEmpty(url))
            {
                throw new KeyNotFoundException("The configuration key is not found in the config file, please add 'DirectoryAccountService.RootEntryPath' to the appSettings config.");
            }
            connectionName = url.Replace("DB://", "");
            dbContext      = new DbDirectoryAccountContext(connectionName);
#endif
#if NETCORE
            var dir     = Directory.GetCurrentDirectory();
            var builder = new ConfigurationBuilder()
                          .SetBasePath(dir)
                          .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);

            var configuration = builder.Build();
            connectionName   = configuration.GetValue <string>("DirectoryAccountService:connectionString");
            connectionString = configuration.GetConnectionString(connectionName);
            var optionsBuilder = new DbContextOptionsBuilder <DbDirectoryAccountContext>();
            optionsBuilder.UseSqlServer(connectionString);
            dbContext = new DbDirectoryAccountContext(optionsBuilder.Options);
#endif
        }
        public DbDirectoryAccountService(string connectionName) : base(connectionName)
        {
            this.connectionName = connectionName;
#if NET45
            dbContext = new DbDirectoryAccountContext(connectionName);
#endif
#if NETCORE
            var dir     = Directory.GetCurrentDirectory();
            var builder = new ConfigurationBuilder()
                          .SetBasePath(dir)
                          .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);

            var configuration  = builder.Build();
            var optionsBuilder = new DbContextOptionsBuilder <DbDirectoryAccountContext>();
            connectionString = configuration.GetConnectionString(connectionName);
            optionsBuilder.UseSqlServer(connectionString);
            dbContext = new DbDirectoryAccountContext(optionsBuilder.Options);
#endif
        }
        public override void Open()
        {
            if (dbContext == null)
            {
#if NET45
                dbContext = new DbDirectoryAccountContext(connectionName);
#endif
#if NETCORE
                var optionsBuilder = new DbContextOptionsBuilder <DbDirectoryAccountContext>();
                optionsBuilder.UseSqlServer(connectionString);
                dbContext = new DbDirectoryAccountContext(optionsBuilder.Options);
#endif
            }
            else
            {
#if NET45
                dbContext.Database.Connection.Open();
#endif
#if NETCORE
                dbContext.Database.OpenConnectionAsync();
#endif
            }
        }
 public DbDirectoryAccountService(DbContextOptions options)
 {
     dbContext = new DbDirectoryAccountContext(options);
 }