简体   繁体   中英

entity framework 5 codefirst with mysql

can ef5 work with mysql when using code first approach? when i'm trying to add new items to a not yet created table I'm getting "Table 'clients' doesn't exist. if I'm switching to mssql everything works well.

this is my dbcontext

    public class MyDBContext : DbContext
{
    public PowerToolsDBContext()
        : base("Name=MyContext") { }

    public DbSet<User> Users { get; set; }
    public DbSet<Client> Clients { get; set; }
    public DbSet<JobData> Jobs { get; set; }
}

Problem solved after adding database initializer

 static MyDBContext()
    {
        Database.SetInitializer<MyDBContext>(new DropCreateDatabaseIfModelChanges<MyDBContext>());
    }

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM