Database Migration MembershipReboot

150 Views Asked by At

I'm working for the first time with Membership Reboot and I have custom class. I added a new property called Middle Name. How can I do the EF Migration on this to get it updated?

public class CustomUser : RelationalUserAccount
{
    [Display(Name = "First Name")]
    public virtual string FirstName { get; set; }
    [Display(Name = "Last Name")]
    public virtual string LastName { get; set; }
    [Display(Name = "Middle Name")]
    public virtual string MiddleName { get; set; }
    public virtual int? Age { get; set; }

}

public class CustomUserAccountService : UserAccountService<CustomUser>
{
    public CustomUserAccountService(CustomConfig config, CustomUserRepository repo)
        : base(config, repo)
    {
    }
}

public class CustomUserRepository : DbContextUserAccountRepository<CustomDatabase, CustomUser>
{
    public CustomUserRepository(CustomDatabase ctx)
        : base(ctx)
    {
    }
}
1

There are 1 best solutions below

1
On
  1. Open package manager console
  2. Run Enable-Migrations command for your project
  3. Add an initial migration before changing any properties to set the initial state in your project

    add-migration -Name Initial

  4. Create the initial table structure in the database.

    Update-Database

  5. Add the MiddleName property in the customUser class

  6. Add new migration for the changes you have done.

    add-migration -Name middleName_added

  7. Update the database to reflect the new changes in database

    Update-Database

  8. Run steps 5-7 as you updating the properties of CustomUser