表'DBNAME.dbo.TableNAME'不存在实体框架6与MySQL [英] Table 'DBNAME.dbo.TableNAME' doesn't exist Entity Framework 6 with MySQL

查看:699
本文介绍了表'DBNAME.dbo.TableNAME'不存在实体框架6与MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用实体框架6.0.0与MySQL 5.6.17服务器



我走过的NuGet添加MySql.Data.Entities并安装实体框架6.0.0和MySql.Data 6.8.4



一切都建立完美,做工精致一些我的业务实体。它启用了自动迁移(真)。



后来我增加了一些更多的实体,然后它开始给错误,如

 表DBNAME.dbo.TABLENAME'不存在实体框架6 

我曾尝试删除整个数据库,再重新创建它,但它并没有奏效。



我曾尝试更新实体框架6.1.2和MySQL 。数据为6.9.5,但它并没有解决问题,但给出了一些其他错误,比如

 找不到方法:System.Data这.Entity.Migrations.Builders.TableBuilder`1<!0 GT; System.Data.Entity.Migrations.Builders.TableBuilder`1.Index(System.Linq.Expressions.Expression`1< System.Func`2<!0,System.Object的>>中System.String,布尔,布尔, System.Object的)。 



所以我改变了我的EF和MySql.Data到以前的版本(6.0.0 EF和MySql.Data 6.8.4)



我发现多了一个文章的 http://bugs.mysql.com/bug.php?id=69649 谁拥有同样的错误,像我这样的
,所以我修改了我的配置方法如下

 公共配置()
{
this.AutomaticMigrationsEnabled = TRUE;
SetSqlGenerator(MySql.Data.MySqlClient,新MySql.Data.Entity.MySqlMigrationSqlGenerator());
CodeGenerator =新MySql.Data.Entity.MySqlMigrationCodeGenerator();
AutomaticMigrationDataLossAllowed = TRUE; //或万一丢失数据假是不允许的。
}



但它并没有解决问题。我再次得到了同样的错误。



我的样本业务实体是如下图所示。

 公共类用户
{
[关键]
公众诠释用户名{搞定;组; }
[显示(名称=用户电子邮件)]
[AllowHtml]
公共字符串USEREMAIL {搞定;组; }
[最大长度(100)]
[必需(的ErrorMessage =输入用户密码)]
[显示(名称=用户密码)
[AllowHtml]
酒店的公共字符串的userPassword {搞定;组; }
[最大长度(50)]
[显示(名称=名)
[AllowHtml]
公共字符串名字{获得;组; }
[最大长度(50)]
[显示(名称=姓氏)]
[AllowHtml]
公共字符串名字{获得;组; }
[显示(NAME =头像)]
公共字符串ProfilePicURL {搞定;组; }
公共字符串saltKey的{搞定;组; }
}

感谢您提前


任何帮助< DIV CLASS =h2_lin>解决方案

 类SqlGenerator:MySql.Data.Entity.MySqlMigrationSqlGenerator 
{
公共覆盖的IEnumerable< MigrationStatement>生成(IEnumerable的< MigrationOperation> migrationOperations,串providerManifestToken)
{
IEnumerable的< MigrationStatement> RES = base.Generate(migrationOperations,providerManifestToken);
的foreach(在res MigrationStatement毫秒)
{
ms.Sql = ms.Sql.Replace(DBO,);
}
返回水库;
}
}
(...)
SetSqlGenerator(MySql.Data.MySqlClient,新SqlGenerator());

更好的解决方案:
当我重新启动应用程序时,EF总是想删除然后创建外键约束一个更多的时间,这一切奇怪的SQL操作中含有DBO。架构。我不理会他们。

 的foreach(在res MigrationStatement毫秒)
{
//ms.Sql = ms.Sql.Replace(DBO。,);
如果(ms.Sql.Contains(DBO))
{
返回新的List< MigrationStatement>();
}
}


I am using Entity Framework 6.0.0 with MySql Server 5.6.17

I have added MySql.Data.Entities through nuget and it installed Entity Framework 6.0.0 and MySql.Data 6.8.4

Everything was setup perfectly and working fine with some of my Business Entities. it have automigration enabled(true).

Later i have added some more entities and then it started giving error like

Table 'DBNAME.dbo.TABLENAME' doesn't exist Entity Framework 6

I have tried deleting whole database and recreate it again, but it didn't worked.

I have tried updating Entity Framework to 6.1.2 and MySql.Data to 6.9.5 but it did not solved problem but gives some other error like

Method not found: 'System.Data.Entity.Migrations.Builders.TableBuilder`1<!0> System.Data.Entity.Migrations.Builders.TableBuilder`1.Index(System.Linq.Expressions.Expression`1<System.Func`2<!0,System.Object>>, System.String, Boolean, Boolean, System.Object)'.

So i changed my EF and MySql.Data to previous version(EF 6.0.0 And MySql.Data 6.8.4)

I found one more article http://bugs.mysql.com/bug.php?id=69649 who has same error like me so i modified my configuration method as below

 public Configuration()
 {
            this.AutomaticMigrationsEnabled = true;
            SetSqlGenerator("MySql.Data.MySqlClient", new MySql.Data.Entity.MySqlMigrationSqlGenerator());
            CodeGenerator = new MySql.Data.Entity.MySqlMigrationCodeGenerator();
            AutomaticMigrationDataLossAllowed = true;  // or false in case data loss is not allowed.
 }

but it did not solved issue. i got same error again.

My Sample Business Entity is as below.

public class User
{
    [Key]
    public int UserID { get; set; }
    [Display(Name = "User Email")]
    [AllowHtml]
    public string UserEmail { get; set; }
    [MaxLength(100)]
    [Required(ErrorMessage = "Enter user password")]
    [Display(Name = "User Password")]
    [AllowHtml]
    public string UserPassword { get; set; }
    [MaxLength(50)]
    [Display(Name = "First Name")]
    [AllowHtml]
    public string FirstName { get; set; }
    [MaxLength(50)]
    [Display(Name = "Last Name")]
    [AllowHtml]
    public string LastName { get; set; }
    [Display(Name = "Profile Picture")]
    public string ProfilePicURL { get; set; }
    public string SaltKey { get; set; }
}

Thanks for any help in advance

解决方案

class SqlGenerator : MySql.Data.Entity.MySqlMigrationSqlGenerator
{
    public override IEnumerable<MigrationStatement> Generate(IEnumerable<MigrationOperation> migrationOperations, string providerManifestToken)
    {
        IEnumerable < MigrationStatement > res =  base.Generate(migrationOperations, providerManifestToken);
        foreach(MigrationStatement ms in res)
        {
            ms.Sql = ms.Sql.Replace("dbo.","");
        }
        return res;
    }
}
(...)
SetSqlGenerator("MySql.Data.MySqlClient", new SqlGenerator());

Better solution: When i restart application, EF always want to drop and create foreign key constraint one more time, all this strange sql operations contains "dbo." schema. I just ignore them.

foreach(MigrationStatement ms in res)
{
    //ms.Sql = ms.Sql.Replace("dbo.","");
    if(ms.Sql.Contains("dbo."))
    {
        return new List<MigrationStatement>();
    }
}

这篇关于表'DBNAME.dbo.TableNAME'不存在实体框架6与MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆