How to use migration in code first entity framework?

I am facing a problem while using code first approach in MVC. I have made the class of employee, context class and connection string. Still my database not generated. I don’t know how to use migration. See the code below:

Thanks in advance 

Employee class

public class Employee   
    public int ID { get; set; }
        public string EmpName { get; set; }
        public int Salary { get; set; } } 

Context class 

public class DepartmentDB_Context: DbContext
    public DepartmentDB_Context() : base("DepartmentDB_Context") { }
        public DbSet<Employee> EmployeeTable { get; set; } } 


    <add name="DepartmentDB_Context" connectionString="data source=.; User Id=sa; Password=1234; initial catalog=DepartmentDB_Context;" providerName="System.Data.SqlClient"/>

Last updated:9/12/2017 4:36:49 AM

1 Answers

Samuel Fernandes
Samuel Fernandes

You need to enable migration from package manager console and add migration

First step is to enable migration to enable migration type following command in package console manager

PM> enable-migrations

Second step is to add migration use following command

PM> add-migration v1

Third step is to update database for updating migration use following command                                              

PM> update-database v1

 I hope your problem will be solved after using these step