本文整理汇总了C#中IDbContext.ValidateSchema方法的典型用法代码示例。如果您正苦于以下问题:C# IDbContext.ValidateSchema方法的具体用法?C# IDbContext.ValidateSchema怎么用?C# IDbContext.ValidateSchema使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDbContext
的用法示例。
在下文中一共展示了IDbContext.ValidateSchema方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Init
public static void Init(DatabaseInitMethod structureBootstrap,
IDbContext factory, IComponentContext ctx)
{
IndexRepository indexRepo = null;
if (ctx.IsRegistered<IndexRepository>())
{
//cant take from context because IDbContext is initializing
indexRepo = new IndexRepository(factory, log);
}
log.Info(String.Format("Initializing DB {0} {1} index module",
structureBootstrap, (indexRepo==null?"without":"with")));
switch (structureBootstrap)
{
case DatabaseInitMethod.DoNothing:
if(indexRepo!=null)
{
indexRepo.IndexManagers.ForEach(x => x.Optimize());
}
break;
case DatabaseInitMethod.Recreate:
var schema = factory.GetSchemaExport();
schema.Create(true, true);
if (indexRepo != null)
{
indexRepo.IndexManagers.ForEach(x => x.Fill());
}
break;
case DatabaseInitMethod.FailIfInvalid:
try
{
factory.ValidateSchema();
}
catch (Exception ex)
{
throw new Exception("FailIfInvalid valiadtion failed", ex);
}
Init(DatabaseInitMethod.DoNothing, factory, ctx);
break;
case DatabaseInitMethod.CreateIfInvalid:
var newstructureBootstrapMethod = DatabaseInitMethod.DoNothing;
//Test connection
try
{
factory.ValidateSchema();
if (indexRepo != null)
{
indexRepo.IndexManagers.ForEach(x => x.Purge());
indexRepo.IndexManagers.ForEach(x => x.Fill());
}
}
catch (Exception ex)
{
log.Debug("CreateIfInvalid valiadtion failed");
log.Debug(ex);
newstructureBootstrapMethod = DatabaseInitMethod.Recreate;
}
Init(newstructureBootstrapMethod, factory, ctx);
break;
}
}