dbo mysql中有没有,表'DBNAME.dbo.TableNAME'不存在实体框架6与MySQL

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 System.Data.Entity.Migrations.Builders.TableBuilder`1.Index(System.Linq.Expressions.Expression`1>, 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 Generate(IEnumerable 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();

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值