public GenericRepository(EcologyContext context) { this.context = context ?? throw new ArgumentException("An instance of DbContext is required to use this repository.", "context"); this.DbSet = context.Set <T>(); }
public static void SeedData(EcologyContext ecologyContext, MasterContext masterContext) { bool databaseExists = (ecologyContext.GetService <IDatabaseCreator>() as RelationalDatabaseCreator).Exists(); if (!databaseExists) { string filePath = Path.Combine(AppContext.BaseDirectory, "Seed", "Ecology.sql"); string seedSql = File.ReadAllText(filePath); string masterDbConnectionString = masterContext.Database.GetDbConnection().ConnectionString; // Overview (SMO): https://docs.microsoft.com/en-us/sql/relational-databases/server-management-objects-smo/overview-smo?view=sql-server-2017 using (SqlConnection connection = new SqlConnection(masterDbConnectionString)) { Server server = new Server(new ServerConnection(connection)); //https://docs.microsoft.com/en-us/previous-versions/sql/sql-server-2014/ms199350%28v%3dsql.120%29 server.ConnectionContext.ExecuteNonQuery(seedSql); } } }
public SpeciesDistributionRepository(EcologyContext context) : base(context) { this.context = context; }
public UnitOfWork(EcologyContext context) { this.Context = context; }
public RealmRepository(EcologyContext context) : base(context) { this.context = context; }
public CountryRepository(EcologyContext context) : base(context) { this.context = context; }
public SpeciesRepository(EcologyContext context) : base(context) { this.context = context; }
public EcoregionRepository(EcologyContext context) : base(context) { this.context = context; }
public BiomeRepository(EcologyContext context) : base(context) { this.context = context; }
public void SeedData(EcologyContext context, MasterContext masterContext) { DatabaseInitializer.SeedData(context, masterContext); }