Forcing EF 6 to create tables with model first

c# database ef-model-first entity-framework-6

Accepted Answer

Additionally, this is a good tonal zzz-5 zzz

however, if the model is sound, the database should be built by the database strategy that you can specify the first time you visit the dbContext: Database.SetInitializer()\sinitializer set

In brief, you must create classes that derive from DbContext after creating your model.

 public class CompanyContext : DbContext
{
    public CompanyContext() : base("CompanyDatabase") { }

    public DbSet<Collaborator> Collaborators { get; set; }
    public DbSet<Department> Departments { get; set; }
    public DbSet<Manager> Managers { get; set; }
}

then the tables ought to be created when you visit this context. You can also use data from the approach you intend to use to seed the database (see this link: updating a database).

2
1/6/2014 5:16:40 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow