Beispiel #1
0
        public static void BooksDBCreate()
        {
            var dbInitializer = new BooksDBInitializer();

            using (var db = dbInitializer.CreateDbContext(null))
            {
                db.Database.EnsureDeleted();
                db.Database.EnsureCreated();
            }
        }
Beispiel #2
0
        public static void ChangeDBCollate()
        {
            var dbInitializer = new BooksDBInitializer();

            using (var db = dbInitializer.CreateDbContext(null))
            {
                db.Database.ExecuteSqlRaw("ALTER DATABASE CURRENT COLLATE Cyrillic_General_CI_AS");
                SqlConnection.ClearAllPools();
                db.SaveChanges();
            }
        }
Beispiel #3
0
        public static void FillDbWithSqlScript()
        {
            var dbInitializer = new BooksDBInitializer();

            using (var db = dbInitializer.CreateDbContext(null))
            {
                using (var dbContextTransaction = db.Database.BeginTransaction())
                {
                    var script = File.ReadAllText(_WorkPathToSQLScript, Encoding.Default);
                    var parts  = script.Split(new string[] { "GO" }, StringSplitOptions.RemoveEmptyEntries);

                    foreach (var part in parts)
                    {
                        db.Database.ExecuteSqlRaw(part);
                    }

                    db.SaveChanges();
                    dbContextTransaction.Commit();
                }
            }
        }