Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • Code First Approach in .Net - Part 2

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1
    • 0
    • 247
    Comment on it

    Hi Friends,

    I have implemented the code first approach in my last blog if you miss it below is the link.

    Code First Approach in .Net

    There are some points i need to discuss while implementing code first approach.

    If you run the code first approach,first time then it will successfully create the database and table with specified properties.

    If you made some changes in the model then rerun the code it will throw the exception as shown below in the image.


    To resolve this exception you need to enable the migration and add update the database by running the commands on the Package Manager Console as specified below :-


    1. Firstly you need to enable the Migrations. Open the package manager console by following below steps :-
       Tools => NuGet Package Manager => Package Manager Console
       Write the following command:-
       //It will enable the migrations in the database.

    2. Then write the command 
       //it will scaffold the next migration based changes.    


    3. Then write the following command in package manager console

        //It will update the pending changes in the database.


    Have query? Write in the comments.

    Happy Coding!!

    Code First Approach in .Net - Part 2

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: