【发布时间】:2015-03-18 14:55:42
【问题描述】:
我正在使用 Entity Framework 6.0.0 和 MySql Server 5.6.17
我通过 nuget 添加了 MySql.Data.Entities,它安装了 Entity Framework 6.0.0 和 MySql.Data 6.8.4
一切都设置得很完美,并且可以与我的一些业务实体正常工作。它启用了自动迁移(true)。
后来我添加了更多实体,然后它开始给出错误,例如
Table 'DBNAME.dbo.TABLENAME' doesn't exist Entity Framework 6
我尝试删除整个数据库并重新创建它,但没有成功。
我尝试将 Entity Framework 更新到 6.1.2 并将 MySql.Data 更新到 6.9.5,但它没有解决问题但给出了一些其他错误,例如
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)'.
所以我将我的 EF 和 MySql.Data 更改为以前的版本(EF 6.0.0 和 MySql.Data 6.8.4)
我又找到一篇文章http://bugs.mysql.com/bug.php?id=69649 和我有同样的错误 所以我修改了我的配置方法如下
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.
}
但它没有解决问题。我又遇到了同样的错误。
我的示例业务实体如下。
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; }
}
提前感谢您的帮助
【问题讨论】:
-
您的问题被标记为“mysql”。然而,您正在使用与 SQL Server 关联的三部分命名约定。为 MySQL 使用正确的数据库引用或连接到 SQL Server 数据库。
-
@GordonLinoff 这就是我遇到的错误。我没有指定任何类似的 AFAIK
-
我也看到了这个错误。你有想过吗?
标签: c# mysql entity-framework entity-framework-6