public static void FixOnModelCreating(ModelBuilder modelBuilder, Type contextType, ShamanOptions shamanOptions = null) { shamanOptions = shamanOptions ?? ShamanOptions.CreateShamanOptions(contextType); Action <string> log = delegate(string message) { shamanOptions.Logger.Log(typeof(MigrationFixer), nameof(FixOnModelCreating), message); }; log("Before SetRawModel"); try { ModelsCachedContainer.SetRawModel(contextType, modelBuilder.Model, shamanOptions.Logger); log("After SetRawModel"); } catch (Exception e) { shamanOptions.Logger.LogException(Guid.Parse("{8E4EA170-3B75-4491-8074-177E5DC8F671}"), e); log("After SetRawModel with exception " + e.Message); throw; } var fix = fixingHolder.TryFix(contextType, () => { log("Fixing..."); var modelFixer = new ModelCreatingFixer(contextType, shamanOptions); modelFixer.FixOnModelCreating(modelBuilder); }); if (!fix) { log("Skip"); } }
public static void FixOnModelCreating(ModelBuilder modelBuilder, Type contextType, ShamanOptions shamanOptions = null) { shamanOptions = shamanOptions ?? ShamanOptions.CreateShamanOptions(contextType); Action <string> log = message => shamanOptions.Logger.Log(typeof(ModelFixer), nameof(FixOnModelCreating), message); log("Before SetRawModel"); try { ModelsCachedContainer.SetRawModel(contextType, modelBuilder.Model, shamanOptions.Logger); log("After SetRawModel"); } catch (Exception e) { log("After SetRawModel with exception " + e.Message); throw; } var fix = fixingHolder.TryFix(contextType, () => { log("Fixing..."); var modelFixer = new ModelFixer(contextType, shamanOptions); modelFixer.FixOnModelCreating(modelBuilder); }); if (!fix) { log("Skip"); } }
/// <summary> /// Call this method at the end of <see cref="DbContext.OnModelCreating"/> /// </summary> /// <typeparam name="T"></typeparam> /// <param name="modelBuilder"></param> /// <param name="shamanOptions"></param> public static void FixOnModelCreating <T>(this ModelBuilder modelBuilder, ShamanOptions shamanOptions = null) where T : DbContext { if (modelBuilder == null) { throw new ArgumentNullException(nameof(modelBuilder)); } ModelsCachedContainer.SetRawModel(typeof(T), modelBuilder.Model); ModelFixer.FixOnModelCreating(modelBuilder, typeof(T), shamanOptions); }