I tried to use EF6 and MySQL. I am sure the my connection to the database is working because the preferred database schema exists. However, only the __migration table exists.
I have the following codes
My Model
[Table("my_model")]
public class ModelA
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int ModelAId { get; set; }
public string ModelAProperty { get; set; }
}
My DBContext
public class ModelAContext : DbContext
{
public ModelAContext() : base("DefaultConnection")
{
}
static ModelAContext()
{
Database.SetInitializer( new DropCreateDatabaseIfModelChanges<ModelAContext>());
}
public DbSet<ModelA> MyModels { get; set; }
}
My Initializer
// Assuming this is run during the application initialization
public static void InitializeDB()
{
using (var context = new ModelAContext())
{
if (!context.Database.Exists())
{
// Create the SimpleMembership database without Entity Framework migration schema
((IObjectContextAdapter)context).ObjectContext.CreateDatabase();
}
context.Database.CreateIfNotExists();
}
}
The corresponding table for ModelA was not created. I always get a MySQL exception where a table (in this case app.my_model) does not exists.
Any help will be much appreciated.
P.S. If you have any good tutorial where I can setup my MySQL and EF6 in ASP.NET MVC4, it would be great. As of now, I can't seem to use the WebSecurity helper of MVC4.