Nick Gilbert
Nick Gilbert

Reputation: 4240

Reset ASP.NET Identity Database

I have an ASP.NET MVC application which uses ASP.NET Identity. I want to add a feature which resets the database. Here is the layout of the database used by Identity right now

enter image description here

I've created a controller that will contain the code to reset the database

public ActionResult GenerateDatabase()
{
    //Drop all tables
    //Readd all tables
    return RedirectToAction("Register", "Account");
}

But I'm fairly new to working with SQL Server through C#. How can I reset the database through a C# controller (as in drop the tables and readd them)?

Upvotes: 1

Views: 1907

Answers (1)

CodeNotFound
CodeNotFound

Reputation: 23200

You can do all you want via the Database property of your DbContext :

To delete the database just use:

yourDbContextInstance.Database.Delete();

To recreate the databse just use:

yourDbContextInstance.Database.Create(); // Also check CreateIfNotExists()

Upvotes: 1

Related Questions