本文整理汇总了C#中Migrator.MigrateFromModel方法的典型用法代码示例。如果您正苦于以下问题:C# Migrator.MigrateFromModel方法的具体用法?C# Migrator.MigrateFromModel怎么用?C# Migrator.MigrateFromModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Migrator
的用法示例。
在下文中一共展示了Migrator.MigrateFromModel方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Migrate
public bool Migrate(string connectionString, string providerName, IEnumerable<Type> entities, Action<MigratorResult, Type> callbackOnChanges)
{
var bResult = false;
var provider = ProviderFactory.GetProvider(connectionString, providerName);
foreach (var entity in entities)
{
var batch = new BatchQuery(provider);
var m = new Migrator(Assembly.GetExecutingAssembly());
var commands = m.MigrateFromModel(entity, provider);
bResult |= commands.Length > 0;
try
{
foreach (var s in commands)
batch.QueueForTransaction(new QueryCommand(PrepareCommand(s), provider));
batch.ExecuteTransaction();
}
catch(Exception ex)
{
var sb = new StringBuilder(ex.Message);
sb.Append(": ");
foreach (var command in commands)
sb.Append(command);
throw new Exception(sb.ToString(), ex);
}
if (callbackOnChanges == null) continue;
callbackOnChanges(commands.Length > 0 ? MigratorResult.ChangesMadeToEntity : MigratorResult.NoChanges,
entity);
}
if (callbackOnChanges != null)
callbackOnChanges(MigratorResult.ChangesMadeToAllEntities, null);
return bResult;
}