示例#1
0
        public static void PurgeDb(Seed seed)
        {
            ConnectionProfile cp = new ConnectionProfile();
            SqlConnectionStringBuilder conn_orig = new SqlConnectionStringBuilder(cp.ConnectionString);
            SqlConnectionStringBuilder conn = new SqlConnectionStringBuilder(cp.ConnectionString) { ConnectTimeout = 5, InitialCatalog = "master" }; // you can add other parameters.
            using (SqlConnection cnn = new SqlConnection(conn.ConnectionString))
            {
                cnn.Open();

                using (SqlCommand dbCreate = new SqlCommand())
                {
                    dbCreate.CommandText = string.Format(@"IF db_id('{0}') IS NULL CREATE DATABASE [{0}]", conn_orig.InitialCatalog);
                    dbCreate.Connection = cnn;
                    try
                    {
                        dbCreate.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(string.Format("create database [{0}] FAILED with {1}", conn_orig.InitialCatalog, ex.Message ));
                    }
                }
            }

            seed.PurgeDb();
        }
示例#2
0
文件: has_many.cs 项目: adamjmoon/Oak
        void before_each()
        {
            seed = new Seed();

            blogs = new Blogs();

            comments = new Comments();
        }
示例#3
0
 static void Main(string[] args)
 {
     ConnectionProfile.connectionString = @"Server=(localdb)\ProjectsV12; Database=SyncToday2015.new; Trusted_Connection=True;";
     if (args.Length >0) ConnectionProfile.connectionString = args[0];
     //Console.WriteLine(string.Format("Creating database '{0}'", ConnectionProfile.connectionString));
     var seed = new Seed();
     PurgeDb(seed);
     var schema = new Schema(seed);
     schema.Scripts().ForEach<dynamic>(s => { /*Console.WriteLine(s());*/ seed.ExecuteNonQuery(s()); });
 }
示例#4
0
 public string CreateUserTable(Seed seed)
 {
     return seed.CreateTable("Users",
         new { Id = "int", Identity = true, PrimaryKey = true },
         new { Email = "nvarchar(max)" },
         new { FirstName = "nvarchar(max)" },
         new { LastName = "nvarchar(max)" },
         new { Password = "******" }
     );
 }
示例#5
0
文件: Program.cs 项目: eugman/Oak
        static void Main(string[] args)
        {
            if (args.Length == 0) throw new InvalidOperationException("first argument should be a connection string.");

            Console.WriteLine("Purging and regenerating schema for " + args[0] + ".");

            var connection = new ConnectionProfile { ConnectionString = args[0] };

            var seed = new Seed(connection);

            var schema = new Schema(seed);

            seed.PurgeDb();

            seed.ExecuteTo(schema.Scripts(), schema.Current());

            Console.WriteLine("Done.");
        }
示例#6
0
 public Schema(Seed seed)
 {
     Seed = seed;
 }
示例#7
0
        public SeedController()
        {
            Seed = new Seed();

            Schema = new Schema(Seed);
        }
示例#8
0
 void before_each()
 {
     seed = new Seed();
 }
        void SetupSchema()
        {
            seed = new Seed();

            seed.PurgeDb();

            seed.CreateTable("Blogs", new dynamic[]
            {
                new { Id = "int", Identity = true, PrimaryKey = true },
                new { Title = "nvarchar(255)" },
                new { Body = "nvarchar(max)" }
            }).ExecuteNonQuery();

            seed.CreateTable("Comments", new dynamic[]
            {
                new { Id = "int", Identity = true, PrimaryKey = true },
                new { BlogId = "int", ForeignKey = "Blogs(Id)" },
                new { Text = "nvarchar(1000)" }
            }).ExecuteNonQuery();
        }
示例#10
0
 public Schema(Seed seed)
 {
     this.seed = seed;
 }
示例#11
0
 public SeedController()
 {
     Seed = new Seed();
 }