I'm in the process of adapting the MVCMusicStore basket. I want to reorganize the database using EntityFramework - not through Server Explorer.
In my model folder, I created a new FooEntities model.
public class FooStoreEntities : DbContext { public DbSet<Foo> Foos { get; set; } public DbSet<Category> Categories { get; set; } public DbSet<FooMaker> FooMakers { get; set; } public DbSet<Cart> Carts { get; set; } public DbSet<Order> Orders { get; set; } public DbSet<OrderDetail> OrderDetails { get; set; } }
I also created additional models Foo , FooMaker and Category . Other models already existed in the MVCMusicStore example.
I created the SampleFooData class, which inherits from DropCreateDatabaseIfModelChanges<FooStoreEntities> and overrides the seed method to sow new tables.
I changed the Application_Start method in Global.asax.cs containing System.Data.Entity.Database.SetInitializer(new FooStore.Models.SampleFooData());
In the web.config , I have:
<connectionStrings> <add name="FooStoreEntities" connectionString="Data Source=|DataDirectory|FooStore.sdf" providerName="System.Data.SqlServerCe.4.0"/> </connectionStrings>
Where FooStore.sdf still contains all the old tables from the MVCMusicStore application.
When I run the web application, it hits the SetInitializer breakpoint, but it doesn't seem to create a SampleFooData object or create new tables in the database. What am I missing? Or something fundamental I donβt understand?
source share