error "Found invalid data while decoding"

59 Views Asked by At

I am developing an application that uses Entity Framework with MySQL. Not all tables are using Entity Framework; only a few tables are used for RBAC purposes and and the other table im using command text. Everything runs normally the problem occur alwasy after restore database, and i restart the apps when try to login an error show "Found invalid data while decoding".

i deleted the all RBAC table the apps is working, so how to solved this without delete RBAC Table

this is my database setup for rbac only

 #region ------------------------------------ EF DATABASE -----------------------------------
[DbConfigurationType(typeof(MySqlEFConfiguration))]
public class RBACDbContext : IdentityDbContext<ApplicationUser, ApplicationRole, string, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim>
{
    public DbSet<PERMISSION> PERMISSIONS { get; set; }
    public DbSet<LINK_USER_ROLE_ACTION> LNK_USER_ROLE_ACTION{ get; set; }
    public DbSet<LINK_USER_BRANCH> LNK_USER_BRANCH { get; set; }
    public DbSet<ApplicationUserRole> LNK_USER_ROLE{ get; set; }

    public RBACDbContext() : base("DBConnection")
    {
        

    }

    public static RBACDbContext Create()
    {
        var rbacDBContext = new RBACDbContext();
        Database.SetInitializer(new MigrateDatabaseToLatestVersion<RBACDbContext, RBACDatabaseInitializer>());
        return rbacDBContext;

    }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
        
        modelBuilder.Entity<ApplicationUser>().ToTable("USERS").Property(p => p.Id).HasColumnName("UserId");
        modelBuilder.Entity<ApplicationRole>().ToTable("ROLES").Property(p => p.Id).HasColumnName("RoleId");
        modelBuilder.Entity<ApplicationUserRole>().ToTable("LNK_USER_ROLE");
        modelBuilder.Entity<LINK_USER_ROLE_ACTION>().ToTable("LNK_USER_ROLE_ACTION");
        modelBuilder.Entity<LINK_USER_BRANCH>().ToTable("LNK_USER_BRANCH");

        modelBuilder.Entity<ApplicationRole>().
        HasMany(c => c.PERMISSIONS).
        WithMany(p => p.ROLES).
        Map(
            m =>
            {
                m.MapLeftKey("RoleId");
                m.MapRightKey("PermissionId");
                m.ToTable("LNK_ROLE_PERMISSION");
            });
    }
}

and i set AutomaticMigrationsEnabled= true

SOLVED :

i need to set the initializer to null

 var migrationConfiguration = new RBACDatabaseInitializer();
        var migrator = new DbMigrator(migrationConfiguration);
        var getDBMigrations = migrator.GetDatabaseMigrations(); 
        if (getDBMigrations == null || getDBMigrations.Count() == 0)
        {
            migrator.Update();
        }
        else
        {
            Database.SetInitializer<RBACDbContext>(null);
        }
0

There are 0 best solutions below