本文整理汇总了C#中IDbConnection.GetTableName方法的典型用法代码示例。如果您正苦于以下问题:C# IDbConnection.GetTableName方法的具体用法?C# IDbConnection.GetTableName怎么用?C# IDbConnection.GetTableName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDbConnection
的用法示例。
在下文中一共展示了IDbConnection.GetTableName方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RunMigrations
/// <summary>
/// Run all defined data migrations that have not been run yet
/// </summary>
/// <param name="db">current database connection</param>
/// <returns>Count of migrations run</returns>
public static int RunMigrations(IDbConnection db)
{
var migrationsRun = 0;
var migrationTypes = GetMigrationTypes();
var alreadyExecutedMigrations = db.Query<DataMigration>("select * from [{0}]".Fmt(db.GetTableName<DataMigration>())).ToList();
if (!alreadyExecutedMigrations.Any(x => x.Name == typeof(InitializeDbMigration).Name))
{
// Create all data, run data init migration
var schemaBuilder = new SchemaBuilder(db);
schemaBuilder.GenerateSchema(false);
var dataInitMigration = new InitializeDbMigration();
dataInitMigration.Execute(db);
// Populate all migrations as run
var migrations = migrationTypes.Select(x => new DataMigration
{
Name = x.Name
});
return db.BulkInsert(migrations);
}
var scriptedObjectsToRecreate = new List<Type>();
foreach (var migration in migrationTypes.Where(t => !alreadyExecutedMigrations.Any(m => m.Name == t.Name)).Select(x => (IMigration)Activator.CreateInstance(x)).OrderBy(x => x.Order))
{
// Collect the scripted objects to recreate after migrations are run
if (migration.ScriptedObjectsToRecreate != null && migration.ScriptedObjectsToRecreate.Any())
{
foreach (var viewType in migration.ScriptedObjectsToRecreate.Where(viewType => !scriptedObjectsToRecreate.Any(v => v == viewType)))
{
scriptedObjectsToRecreate.Add(viewType);
}
}
migration.Execute(db);
// add migration to database
var migrationData = new DataMigration
{
CreatedOn = DateTime.UtcNow,
Name = migration.GetType().Name
};
db.Save(migrationData);
migrationsRun++;
}
if (scriptedObjectsToRecreate.Any())
{
foreach (var viewType in scriptedObjectsToRecreate)
{
db.RecreateScriptedObject(viewType);
}
}
return migrationsRun;
}
示例2: Execute
public void Execute(IDbConnection db)
{
if (!db.TableExists(db.GetTableName<SiteSettings>()))
{
db.CreateTable<SiteSettings>();
}
else
{
// Append the analytics specific columns
db.AddColumn<SiteSettings>(x => x.AnalyticsProfileId);
db.AddColumn<SiteSettings>(x => x.AnalyticsToken);
}
}
示例3: RunMigrations
/// <summary>
/// Run all defined data migrations that have not been run yet
/// </summary>
/// <param name="db">current database connection</param>
/// <returns>Count of migrations run</returns>
public static int RunMigrations(IDbConnection db)
{
var migrationsRun = 0;
var migrationTypes = GetMigrationTypes();
if (!db.TableExists(db.GetTableName<DataMigration>()))
{
// Create all data, run data init migration
var schemaBuilder = new SchemaBuilder(db);
schemaBuilder.GenerateSchema(false);
var dataInitMigration = new InitializeDbMigration();
dataInitMigration.Execute(db);
// Populate all migrations as run
var migrations = migrationTypes.Select(x => new DataMigration
{
Name = x.Name
});
return db.BulkInsert(migrations);
}
var alreadyExecutedMigrations = db.Query<DataMigration>("select * from [{0}]".Fmt(db.GetTableName<DataMigration>()));
foreach (var migration in migrationTypes.Where(t => !alreadyExecutedMigrations.Any(m => m.Name == t.Name)).Select(x => (IMigration)Activator.CreateInstance(x)).OrderBy(x => x.Order))
{
migration.Execute(db);
// add migration to database
var migrationData = new DataMigration
{
CreatedOn = DateTime.UtcNow,
Name = migration.GetType().Name
};
db.Save(migrationData);
migrationsRun++;
}
return migrationsRun;
}