简体   繁体   English

实体框架5 Codefirst与mysql

[英]entity framework 5 codefirst with mysql

can ef5 work with mysql when using code first approach? 使用代码优先方法时,ef5可以与mysql一起使用吗? 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. 当我尝试向尚未创建的表中添加新项目时,我得到“表'clients'不存在。如果我切换到mssql,一切正常。

this is my dbcontext 这是我的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>());
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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