Today, I am going to cover. How database migrations work in EF7 on the new platform of asp.net 5.
Step 3. Once EF7 is on the place then move to appsettings.json file for the connection string. Update connection string as per your requirement.
Step 4. Now build the application and check solution is build successfully or not.
Step 5. Check Migration folder at the root level and expand it. you will see the migration script already created by the solution for default identity tables.
Now you need to require update database for that migration script. so you need to run the following command on package manager console.
Before executing any command. please check dnx command working or not.
Step 6. Till here we are just looking update the database but now let's check how to migrate the database (I meant how to add/remove fields from existing table)
Step 7. In our example, I have added a new table for the product so need to create migration script for product table.
Following commands need to execute for creating migrations script and update database for same.
Hope you like the cutting edge technology blog post. This post is very useful to newbie in asp.net 5 / Entity Framework 7.
I have created a sample application with Product table. you can find the code from https://github.com/kalpeshsatasiya/EF7Migration
Let's start step by step
Step 1. Create a new project from visual studio 2015 and select asp.net 5 template.
Step 2. Once project created, Open a project.json file and check Entity Framework 7 dependency added or not. if dependency already added then you will see the following line under the "dependencies" tag. if not then add Entity Framework 7 using NuGet package.
"EntityFramework.Commands": "7.0.0-rc1-final"
Step 3. Once EF7 is on the place then move to appsettings.json file for the connection string. Update connection string as per your requirement.
Step 4. Now build the application and check solution is build successfully or not.
Step 5. Check Migration folder at the root level and expand it. you will see the migration script already created by the solution for default identity tables.
Now you need to require update database for that migration script. so you need to run the following command on package manager console.
Before executing any command. please check dnx command working or not.
dnx ef database update
Step 6. Till here we are just looking update the database but now let's check how to migrate the database (I meant how to add/remove fields from existing table)
Step 7. In our example, I have added a new table for the product so need to create migration script for product table.
Following commands need to execute for creating migrations script and update database for same.
dnx ef migrations add [migration name] dnx ef database update
Hope you like the cutting edge technology blog post. This post is very useful to newbie in asp.net 5 / Entity Framework 7.
0 comments:
Post a Comment