Example #1
0
        public void Recreate(object database)
        {
            #region Preconditions

            if (database == null)
                throw new ArgumentNullException(nameof(database));

            #endregion

            foreach (var property in database.GetType().GetProperties())
            {
                var type = property.PropertyType;
                
                if (!type.GetTypeInfo().IsGenericType) continue;

                type = type.GetGenericArguments()[0];
                
                var schema = Schema.Get(type);

                var mainTable = new TableGenerator(schema, db.TypeMap);

                CreateTable(mainTable, true);
          
                // Create the version table
                if (schema.IsVersioned)
                {
                    var versionTable = new TableGenerator(VersionedSchema.Get(type), db.TypeMap);

                    CreateTable(versionTable, true);
                }
            }
        }
Example #2
0
        public void CreateTable(TableGenerator table, bool dropIfExists = false)
        {
            using (var connection = db.GetConnection())
            {
                if (dropIfExists)
                {
                    connection.Execute("DROP TABLE IF EXISTS " + table.Name + ";");
                }

                connection.Execute(table.ToString());
            }
        }