I have created an ASP.net
Core web Application ( .NET Framework
) application and added the Entity Framework 6 to the project.
I have also created my DB context
as follows:
namespace application1
{
Class _Dbcontext : DbContext
{
DbSet<Item> item {get; set;}
DbSet<ItemView> itemView {get; set;}
}
}
I have created the models as follows:
Class Item
{
public int ID {get; set;}
public string Name {get; set;}
List<ItemView> ItemViews {get; set;}
}
Class ItemView
{
public int ID {get; set;}
public string Name {get; set;}
public Item item {get; set;}
}
I have also followed the article found here to set up the project.
when I run the project the database is not generated in the mssqllocaldb
or (localdb)/ProjectsV13
.
I can use help knowing how to set up the ASP.NET
core Web Application (.NET Framework) template to use Entity Framework 6
.
Thanks for the help.
The database is not created until you make the first request to the database: login to the website or the data request. Or you could use special command in the nuget package console:
> update-database
You should do the following: 1. Install Entity Framework 2. Create your model 3. Register your db context with dependency injection in the Startup.ConfigureServices method 4. Create your database: a. Run Add-Migration InitialMigration Note: InitialMigration is a name given by you b. Run Update-Database
Now your database is updated if exists, or created if does not exists...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.