Asp.net data migration using Package Manager Console

If you have created a model in asp.net and you want to create table for that model . For this you can use package manager console of visual studio. please follow following steps

1:- First open PMC From the Tools menu, select NuGet Package Manager > Package Manager Console.

2:- Now add following commands in PMC

Add-Migration myTable
Update-Database

this command generate schema base on model define in DbContext. and update database command generates table in database

Asp.net core build with dependency injections services . when application start these dependencies registered in startup.cs here this command automatically registere dbcontext for this entity set  in dependicies container.

It is done in ConfigureServices method dbcontext of a model contain main functions of Create, Read, Update, Delete, etc for a model

Leave a Reply

Your email address will not be published. Required fields are marked *