Esempio n. 1
0
        private static void BuildModel(string tableName)
        {
            //string dbConnStr = @"Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Password=pass@word1;Initial Catalog=DBTest;Data Source=.\SQL2008R2";
            string dbname = "DBTest";
            //string tableName = "SampleInt";
            //string connStr2 = @"Data Source=.\SQL2008R2;Initial Catalog=DBTest;User ID=sa;Password=pass@word1;Persist Security Info=False;";
            DatabaseLink link = new DatabaseLink(DatabaseType.MSSQLServer, @".\SQL2008R2", dbname, "sa", "pass@word1");
            ServerInfo serverInfo = new ServerInfo(link);
            IDatabaseInfo database = serverInfo.GetDatabase(dbname);

            ITableInfo tbInfo = null;

            foreach (ITableInfo tInfo in database.Tables)
            {
                if (tInfo.LowerName == tableName.ToLower())
                {
                    tbInfo = tInfo;
                    break;
                }
            }

            DbTableCodeGen builder = new DbTableCodeGen();
            string folder = builder.GenModelCode(tbInfo);
            //Process.Start(folder);
        }
Esempio n. 2
0
        private static void BuildTableAccess()
        {
            //string dbConnStr = @"Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Password=pass@word1;Initial Catalog=DBTest;Data Source=.\SQL2008R2";
            string dbname = "DBTest";
            string tableName = "df_TestUser";
            DatabaseLink link = new DatabaseLink(DatabaseType.MSSQLServer, @".\SQL2008R2", dbname, "sa", "pass@word1");
            ServerInfo serverInfo = new ServerInfo(link);
            IDatabaseInfo database = serverInfo.GetDatabase(dbname);

            ITableInfo tbInfo = null;

            foreach (ITableInfo tInfo in database.Tables)
            {
                if (tInfo.LowerName == tableName.ToLower())
                {
                    tbInfo = tInfo;
                    break;
                }
            }

            DbTableCodeGen gen = new DbTableCodeGen();

            //string code = CodeGen.GenForTable("Model.cshtml", tbInfo);

            string code = gen.GenDataAccessCode("TestApp", tbInfo);

            string fileName = System.IO.Path.GetTempFileName();

            System.IO.File.WriteAllText(fileName, code);

            Process.Start("notepad.exe", fileName);
        }