Exemplo n.º 1
0
        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)
            {
                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 ModelFixer(contextType, shamanOptions);
                modelFixer.FixOnModelCreating(modelBuilder);
            });

            if (!fix)
            {
                log("Skip");
            }
        }
Exemplo n.º 2
0
 /// <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));
     }
     ModelFixer.FixOnModelCreating(modelBuilder, typeof(T), shamanOptions);
 }
Exemplo n.º 3
0
 /// <summary>
 /// Call this method at the end of <see cref="DbContext.OnModelCreating"/>
 /// </summary>
 /// <param name="context"></param>
 /// <param name="modelBuilder"></param>
 /// <param name="shamanOptions"></param>
 public static void FixOnModelCreating(this DbContext context, ModelBuilder modelBuilder, ShamanOptions shamanOptions = null)
 {
     if (context == null)
     {
         throw new ArgumentNullException(nameof(context));
     }
     ModelFixer.FixOnModelCreating(modelBuilder, context.GetType(), shamanOptions);
 }
Exemplo n.º 4
0
 public static void FixOnModelCreating(ModelBuilder modelBuilder, Type contextType,
                                       ShamanOptions shamanOptions = null)
 {
     fixingHolder.TryFix(contextType, () =>
     {
         var modelFixer = new ModelFixer(contextType, shamanOptions);
         modelFixer.FixOnModelCreating(modelBuilder);
     });
 }