Ejemplo n.º 1
0
        /// <summary>
        /// Drops all tables from the database, and the creates new
        /// tables.
        /// </summary>
        protected void BuildTables()
        {
            // Wrap in a transaction
            using (SQLiteTransaction tr = base.BeginTransaction())
            {
                // Delete old table rementants
                CodeFirstSQLite.DropTable <TruckEngine>(this);
                CodeFirstSQLite.DropTable <TruckTransmission>(this);
                CodeFirstSQLite.DropTable <TransmissionGear>(this);
                CodeFirstSQLite.DropTable <AccessoryConflict>(this);
                CodeFirstSQLite.DropTable <SuitableAccessory>(this);
                CodeFirstSQLite.DropTable <Transmission>(this);
                CodeFirstSQLite.DropTable <TransmissionSeries>(this);
                CodeFirstSQLite.DropTable <TorqueRatio>(this);
                CodeFirstSQLite.DropTable <Engine>(this);
                CodeFirstSQLite.DropTable <EngineSeries>(this);
                CodeFirstSQLite.DropTable <EngineSound>(this);
                CodeFirstSQLite.DropTable <EngineSoundPackage>(this);
                CodeFirstSQLite.DropTable <TruckSound>(this);
                CodeFirstSQLite.DropTable <TruckSoundPackage>(this);
                CodeFirstSQLite.DropTable <TruckSoundSetting>(this);
                CodeFirstSQLite.DropTable <Truck>(this);
                CodeFirstSQLite.DropTable <DbVersion>(this);

                // Create the needed database tables
                CodeFirstSQLite.CreateTable <DbVersion>(this);
                CodeFirstSQLite.CreateTable <TruckSoundPackage>(this);
                CodeFirstSQLite.CreateTable <TruckSound>(this);
                CodeFirstSQLite.CreateTable <EngineSeries>(this);
                CodeFirstSQLite.CreateTable <EngineSoundPackage>(this);
                CodeFirstSQLite.CreateTable <EngineSound>(this);
                CodeFirstSQLite.CreateTable <Engine>(this);
                CodeFirstSQLite.CreateTable <Truck>(this);
                CodeFirstSQLite.CreateTable <TorqueRatio>(this);
                CodeFirstSQLite.CreateTable <TruckEngine>(this);
                CodeFirstSQLite.CreateTable <TransmissionSeries>(this);
                CodeFirstSQLite.CreateTable <Transmission>(this);
                CodeFirstSQLite.CreateTable <SuitableAccessory>(this);
                CodeFirstSQLite.CreateTable <AccessoryConflict>(this);
                CodeFirstSQLite.CreateTable <TransmissionGear>(this);
                CodeFirstSQLite.CreateTable <TruckTransmission>(this);
                CodeFirstSQLite.CreateTable <TruckSoundSetting>(this);

                // Create version record
                DbVersion version = new DbVersion();
                version.Version   = CurrentVersion;
                version.AppliedOn = DateTime.Now;

                DbVersions = new DbSet <DbVersion>(this);
                DbVersions.Add(version);

                // Commit the transaction
                tr.Commit();
            }
        }
Ejemplo n.º 2
0
        internal void GetVersion()
        {
            // Grab version. Plain SQL query here for performance
            string    query = "SELECT * FROM DbVersion ORDER BY UpdateId DESC LIMIT 1";
            DbVersion row   = Query <DbVersion>(query).FirstOrDefault();

            // If row is null, then the table exists, but was truncated
            if (row == null)
            {
                throw new Exception("DbVersion table is empty");
            }

            // Set instance database version
            DatabaseVersion = row.Version;
        }