user1679941
user1679941

Reputation:

How are the new membership tables created in ASP MVC5

I have created a number of examples but can't find how the new tables are created. I am familiar with the code first approach and with the way they are automatically created with MVC4.

Can anyone point out the areas of code where they are created in MVC5.

Also I would like to change the context that's currently "defaultcontext". Again I cannot seem to find where this is set up in the new MVC5. I can see what's set up in the web.config but cannot find what references this in my C# code.

Help would be much appreciated.

Upvotes: 0

Views: 1423

Answers (2)

kkakkurt
kkakkurt

Reputation: 2800

For creating new tables, firstly you should add your model.

For example: (AppUsersModel.cs)

public class AppUsersModel
{
    public int ID { get; set; }

    public string UserName { get; set; }

    public int UserPassword { get; set; }
}

After that you should add your DbContext parameters:

public class ApplicationDbContext : DbContext
{
    public ApplicationDbContext()
        : base("DefaultConnection")
    {
    }

    public DbSet<AppUsersModel> AppUsers { get; set; }
}

So you want to manage your model and you should add a controller for your model; For example: (AppUsersController.cs)

public class AlbumController : Controller
{
    private ApplicationDbContext db = new ApplicationDbContext();


    public ActionResult Index()
    {
        return View(db.AppUsers.ToList());
    }
}

(You can edit your view in Views menu.)

After that, open your "Package-Manager Console", Write these codes:

  1. Enable-Migrations
  2. Add-Migration Init
  3. Update-Database

Refresh your database connection and you can see your new table.

Upvotes: 1

Hao Kung
Hao Kung

Reputation: 28200

They are created using EF Code First, specifically the UserStore constructor takes in an instance of a DbContext, by default if no DbContext is passed in, it will create an IdentityDbContext which is what automatically creates the tables via EF Code First.

Upvotes: 0

Related Questions