Esempio n. 1
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
            MySqlConnectionStringBuilder builder = new MySqlConnectionStringBuilder(ConfigurationManager.ConnectionStrings["db"].ConnectionString);
            Boycott.Configuration.DatabaseProvider = new MySQLProvider(builder.Server, builder.Database, builder.UserID, builder.Password);

            WorldUnits wu;
            var sync = new Synchronizator();
            if (!sync.DatabaseExists)
            {
                Boycott.Configuration.DatabaseProvider.CreateDatabase();
                sync.Sync();
                Seed();
            }
            else if (sync.Check())
            {
                sync.Sync();
            }
        }
Esempio n. 2
0
        public static void Main(string[] args)
        {
            Configuration.DatabaseProvider = new MySQLProvider("localhost", "boycott", "root", "root");

            var sync = new Synchronizator();
            if (!sync.DatabaseExists) {
                Configuration.DatabaseProvider.CreateDatabase();
            }

            if (sync.Check()) {
                sync.Sync();
            }

            var expression = (from b in Book.db
                select b);

            if (expression == null) {
                System.Console.WriteLine("null");
            } else {
                System.Console.WriteLine(expression.GetType().Name);
            }

            expression = (from b in Book.db
                join a in Author.db on b.AuthorId equals a.Id
                select b);

            if (expression == null) {
                System.Console.WriteLine("null");
            } else {
                System.Console.WriteLine(expression.GetType().Name);
            }

            var list = expression.ToList();

            var total = Author.db.Count();

            foreach (Book b in Book.All())
            {
                Book.Delete(b.Id);
            }
            new Book() { Id = 1, Name = "O Senhor dos anéis" }.Save();
            new Book() { Id = 2, Name = "O Legado de Joran" }.Save();
            new Book() { Id = 3, Name = "C#" }.Save();
            new Book() { Id = 4, Name = "O Senhor dos anéis" }.Save();
            List<Book> books = Book.FindAll(new {Name = "O Legado de Joran"});
            Book book = Book.Find(2);
            List<Book> books_lotr = Book.FindAll(new { Name = "O Senhor dos anéis" } );

            System.Console.WriteLine("Hello World!");
            System.Console.Read();
        }
Esempio n. 3
0
 public void ProcessRequest(HttpContext context)
 {
     var sync = new Synchronizator();
     if (context.Request.Path.Equals("/activerecord/migration")) {
         context.Response.Write("ok, I gotcha!<br/>\n");
         if (sync.DatabaseExists) {
             sync.Initialize();
             context.Response.Write("<table>");
             foreach (var item in sync.Tables) {
                 context.Response.Write("<tr><td>");
                 context.Response.Write(item.Name);
                 context.Response.Write("</td><td>");
                 context.Response.Write(item.Check());
                 context.Response.Write("</td><td>");
                 if (item.Check()) {
                     context.Response.Write(item.GetDiff());
                 }
                 context.Response.Write("</td></tr>");
             }
             context.Response.Write("</table>");
             context.Response.Write("<a href=\"/activerecord/migrate\">migrate</a>");
         } else {
             context.Response.Write("Database do not exist!<br/>");
             context.Response.Write("<a href=\"/activerecord/database_create\">create database</a>");
         }
     } else if (context.Request.Path.Equals("/activerecord/migrate")) {
         sync.Initialize();
         context.Response.Write("migrate it<br/>\n");
         foreach (var item in sync.Tables) {
             if (item.Check()) {
                 foreach (var sql in item.GetDiff().ToSql()) {
                     context.Response.Write(sql);
                     context.Response.Write("<br/>\n");
                 }
             }
         }
         if (sync.Sync()) {
             context.Response.Redirect("/activerecord/migration");
         }
         context.Response.Write("Done!");
     } else if (context.Request.Path.Equals("/activerecord/database_create")) {
         try {
             Configuration.DatabaseProvider.CreateDatabase();
             context.Response.Redirect("/activerecord/migration");
         } catch (Exception ex) {
             context.Response.Write(ex);
         }
     }
 }