Entity Framework code first, isn't creating the database

后端 未结 2 692
旧时难觅i
旧时难觅i 2020-12-10 03:51

Here\'s an overview of how my solution looks:

\"enter

Here\'s my PizzaSoftware

2条回答
  •  我在风中等你
    2020-12-10 04:26

    Instead of putting this code into main method:

    Database.SetInitializer(new CreateDatabaseIfNotExists());
    

    Put it into DBContext:

    namespace PizzaSoftware.Data
    {
    public class PizzaSoftwareData : DbContext
    {
            public PizzaSoftwareData()
            : base("name=PizzaSoftwareData")
            {
            Database.SetInitializer(new CreateDatabaseIfNotExists());
            }
            public DbSet Customers { get; set; }
            public DbSet Orders { get; set; }
            public DbSet Products { get; set; }
            public DbSet Users { get; set; }
        }
    }
    

提交回复
热议问题