Пример #1
0
        private static void CheckDatabase()
        {
            // Specify the local database connection string.
            const string dbConnectionString = "Data Source=isostore:/rayzitDB.sdf";

            // Create the database if it does not exist.
            using (var db = new RayzDataContext(dbConnectionString))
            {
                if (db.DatabaseExists() == false)
                {
                    // Create the local database.
                    db.CreateDatabase();
                    // Set the new database version.
                    var dbUpdater = db.CreateDatabaseSchemaUpdater();
                    dbUpdater.DatabaseSchemaVersion = AppVersion;
                    dbUpdater.Execute();
                }
                else
                {
                    // Check whether a database update is needed.
                    var dbUpdater = db.CreateDatabaseSchemaUpdater();

                    if (dbUpdater.DatabaseSchemaVersion < AppVersion)
                    {
                        // Delete the local database.
                        db.DeleteDatabase();

                        // Create the local database.
                        db.CreateDatabase();

                        // Perform version 2.0 update, as applicable.
                        if (dbUpdater.DatabaseSchemaVersion < 2)
                        {
                            // Add the Priority column (added in version 2.0).
                            dbUpdater.AddColumn <Rayz>("Geohash");
                            // Add the Priority index (added in version 2.0).
                            try
                            {
                                dbUpdater.AddIndex <Rayz>("GeohashIndex");
                            }
                            catch
                            {
                                //ignore it
                            }
                        }

                        // Set the new database version.
                        dbUpdater.DatabaseSchemaVersion = AppVersion;

                        // Perform the database update in a single transaction.
                        dbUpdater.Execute();
                    }
                }
            }

            // Create the ViewModel object.
            ViewModel = new MainViewModel(dbConnectionString);

            ViewModel.LoadCollectionsFromDatabase();
        }
Пример #2
0
        private static void CheckDatabase()
        {
            // Specify the local database connection string.
            const string dbConnectionString = "Data Source=isostore:/rayzitDB.sdf";

            // Create the database if it does not exist.
            using (var db = new RayzDataContext(dbConnectionString))
            {
                if (db.DatabaseExists() == false)
                {
                    // Create the local database.
                    db.CreateDatabase();
                    // Set the new database version.
                    var dbUpdater = db.CreateDatabaseSchemaUpdater();
                    dbUpdater.DatabaseSchemaVersion = AppVersion;
                    dbUpdater.Execute();
                }
                else
                {
                    // Check whether a database update is needed.
                    var dbUpdater = db.CreateDatabaseSchemaUpdater();

                    if (dbUpdater.DatabaseSchemaVersion < AppVersion)
                    {
                        // Delete the local database.
                        db.DeleteDatabase();

                        // Create the local database.
                        db.CreateDatabase();
                        // Set the new database version.
                        dbUpdater.DatabaseSchemaVersion = AppVersion;
                        dbUpdater.Execute();
                    }
                }
            }

            // Create the ViewModel object.
            ViewModel = new MainViewModel(dbConnectionString);

            ViewModel.LoadCollectionsFromDatabase();
        }