0

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)
    {
    }
}
Tom Kurian
  • 113
  • 13

1 Answers1

0
  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
rawel
  • 2,923
  • 21
  • 33
  • by the way, if you don't need to do migrations, and you don't care about the data in your dev environment, you can delete the whole database. Next time you run the project it will create a new database with your new properties. – rawel Jun 15 '16 at 04:33