Exemplo n.º 1
0
        public bool InitializeContext(IConfigurationRoot configuration)
        {
            string connectionString = configuration.GetConnectionString("LabManDbContext");
            var    configs          = configuration.AsEnumerable();
            bool   useMySql         = false;

            foreach (KeyValuePair <string, string> config in configs)
            {
                if (config.Key.Equals("UseMySql") && config.Value.Equals("Yes"))
                {
                    useMySql = true;
                }
            }
            var optionsBuilder = new DbContextOptionsBuilder();

            if (useMySql)
            {
                connectionString = configuration.GetConnectionString("LabManDbContextMysql");
                optionsBuilder.UseMySQL(connectionString);
            }
            else
            {
                optionsBuilder.UseSqlServer(connectionString);
            }


            dbContext = new LabManDBContext(optionsBuilder.Options);

            if (dbContext.Database.EnsureCreated())
            {
                InitTablesWithData();
                dbContext.SaveChanges();
            }
            return(true);
        }
Exemplo n.º 2
0
        public EFGenericRepository(LabManDBContext dbContext)
        {
            this.dbContext = dbContext;
            this.dbSet     = this.dbContext.Set <T>();

            this.dbContext.SaveChanges();
        }
 public EFStudentsRepository(LabManDBContext dbContext) : base(dbContext)
 {
     base.dependenciesToLoadList = new List <string> {
         "Group", "Grades"
     };
 }
Exemplo n.º 4
0
 public EFGradesRepository(LabManDBContext dbContext) : base(dbContext)
 {
 }