Exemplo n.º 1
0
        static void Main(string[] args)
        {
            string exePath          = @"F:\C_shap\Git\MyORM\trunk\TestApp";
            string mySQL_conStr     = "Your MySQL connection string";
            string sqlServer_conStr = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=" + exePath + @"\TestDataBases\SQLServerDB.mdf" + ";Integrated Security=True;Connect Timeout=30";
            string sqlite_conStr    = @"Data Source=" + exePath + @"\TestDataBases\SQLiteDB.db";

            // step 1  SetConnectionString
            MySQLService.SetConnection(mySQL_conStr);
            SQLServerService.SetConnection(sqlServer_conStr);
            SQLiteService.SetConnection(sqlite_conStr);

            DataBaseTypesEnum DBType  = DataBaseTypesEnum.SQLite;
            SQLService        service = null;

            switch (DBType)
            {
            case DataBaseTypesEnum.MySQL:
            {
                //step 2 tell Service that which type of database you want to use in default
                ModelBase.SetDefaultService(DataBaseTypesEnum.MySQL);

                //step 3 create a new instance and use it
                service = new MySQLService();
                break;
            }

            case DataBaseTypesEnum.SQLServer:
            {
                ModelBase.SetDefaultService(DataBaseTypesEnum.SQLServer);
                service = new SQLServerService();
                break;
            }

            case DataBaseTypesEnum.SQLite:
            {
                ModelBase.SetDefaultService(DataBaseTypesEnum.SQLite);
                service = new SQLiteService();
                break;
            }
            }

            LoadById(service);

            ReadAll(service);

            ReadByCondition(service);

            ReadPageList(service);

            Update(service);

            Insert(service);

            Delete(service);

            Console.ReadKey();
        }