1

I have made a project in which i have choose MVC + Web Api template with Authorized attribute.I have made my SQL Data base on Windows Azure and publish my project successfully.I can see the data of the registered user in users table. Now i wanted to add one more table to my Database but i am not getting how to do it.I know i have to make a model of that table type and update the database.But i don't getting how to write this part in code.I am total newbie in this part. I have seen Account controller class it is looking just an alien to me :)

can somebody help me.

1 Answer 1

3

Step 1: Create the model for your table

public class Comment
{
    public int ID { get; set; }
    public string Content { get; set; }
    public DateTime DateCreated { get; set; }
    public virtual ApplicationUser Author { get; set; }
}

Step2: Add a dbSet for this model in your DbContext class

public class DDBContext : DbContext
{
    public DDBContext()
    {
      /* ... */
    }
    // add the DbSet
    public DbSet<Comment> Comments { get; set; }
    //... additional models ommitted

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        Database.SetInitializer(new MigrateDatabaseToLatestVersion<DDBContext, Configuration>());
    }
}

Step 3: Enable Migrations

In the packagemanager console issue those commands:

enable-migrations
add-migration MyNewTableAdded

Step 4: Build the project

Step 5: Issue the update-database command in the packagemanager console

There is a detailed explanation on www.asp.net including the process for Azure. Click here!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.