mysql 5.5 .net_MySQL 5.5 + .NET连接器+实体框架+ Migrations = FormatException

我试图为我的问题找到一个解决方案,但直到现在我的努力都是徒劳的。 :-(

我使用Visual Studio 2010,.NET Framework 4,C#,Entity Framework 5.0,MySQL 5.5以及相应的.NET连接器(版本6.5.4)创建了一个Web项目。我为实体和O / R映射使用了代码优先方法。

我面临的问题是我无法执行看似简单的迁移。这是我的实体类:

public class Usuario

{

public int Id { get; set; }

[Required]

[StringLength(100)]

public string NomeCompleto { get; set; }

[Required]

[StringLength(100)]

[DataType(DataType.EmailAddress)]

public string Email { get; set; }

[Required]

[StringLength(30)]

public string Login { get; set; }

[Required]

[StringLength(64)]

public string Senha { get; set; }

[Required]

public bool Ativo { get; set; }

//[Timestamp]

[ConcurrencyCheck]

public int Versao { get; set; }

}

public class Perfil

{

public int Id { get; set; }

[Required]

[StringLength(50)]

public string Nome { get; set; }

[StringLength(100)]

public string Descricao { get; set; }

//[Timestamp]

[ConcurrencyCheck]

public int Versao { get; set; }

public virtual ICollection Usuarios { get; set; }

public virtual ICollection Permissoes { get; set; }

}

public class Permissao

{

public int Id { get; set; }

[Required]

[StringLength(50)]

public string Nome { get; set; }

[StringLength(100)]

public string Descricao { get; set; }

//[Timestamp]

[ConcurrencyCheck]

public int Versao { get; set; }

public virtual ICollection Perfis { get; set; }

}由Add-Migration Acesso生成的代码(仅Up()方法):

public partial class Acesso : DbMigration

{

public override void Up()

{

CreateTable(

"dbo.Usuario",

c => new

{

Id = c.Int(nullable: false, identity: true),

NomeCompleto = c.String(nullable: false, storeType: "mediumtext"),

Email = c.String(nullable: false, storeType: "mediumtext"),

Login = c.String(nullable: false, storeType: "mediumtext"),

Senha = c.String(nullable: false, storeType: "mediumtext"),

Ativo = c.Boolean(nullable: false),

Versao = c.Int(nullable: false),

})

.PrimaryKey(t => t.Id);

CreateTable(

"dbo.Perfil",

c => new

{

Id = c.Int(nullable: false, identity: true),

Nome = c.String(nullable: false, storeType: "mediumtext"),

Descricao = c.String(storeType: "mediumtext"),

Versao = c.Int(nullable: false),

})

.PrimaryKey(t => t.Id);

CreateTable(

"dbo.Permissao",

c => new

{

Id = c.Int(nullable: false, identity: true),

Nome = c.String(nullable: false, storeType: "mediumtext"),

Descricao = c.String(storeType: "mediumtext"),

Versao = c.Int(nullable: false),

})

.PrimaryKey(t => t.Id);

CreateTable(

"dbo.PerfilPermissao",

c => new

{

PerfilId = c.Int(nullable: false),

PermissaoId = c.Int(nullable: false),

})

.PrimaryKey(t => new { t.PerfilId, t.PermissaoId })

.ForeignKey("dbo.Perfil", t => t.PerfilId, cascadeDelete: true)

.ForeignKey("dbo.Permissao", t => t.PermissaoId, cascadeDelete: true)

.Index(t => t.PerfilId)

.Index(t => t.PermissaoId);

CreateTable(

"dbo.UsuarioPerfil",

c => new

{

UsuarioId = c.Int(nullable: false),

PerfilId = c.Int(nullable: false),

})

.PrimaryKey(t => new { t.UsuarioId, t.PerfilId })

.ForeignKey("dbo.Usuario", t => t.UsuarioId, cascadeDelete: true)

.ForeignKey("dbo.Perfil", t => t.PerfilId, cascadeDelete: true)

.Index(t => t.UsuarioId)

.Index(t => t.PerfilId);

}

}首先,我必须改变名为Versao(版本)的属性

[Timestamp]

public byte[] Versao { get; set; }至

[ConcurrencyCheck]

public int Versao { get; set; }因为在更改之前发生错误(有关类型rowversion未使用命名空间或别名限定的内容)。在此更改之后,我能够生成迁移,但Update-Database命令失败,并显示以下错误消息:

System.FormatException: Cadeia de entrada não estava em um formato incorreto.

em System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)(输入字符串的格式不正确。)

我试图使用MySQL版本5.5和5.1;连接器的版本6.5.4,6.4.5和6.3.9并不能解决问题。

是否有可能使用MySQL,实体框架和代码优先方法?如果不是,切换到ODBC连接器而不是.NET连接器的后果是什么?

提前致谢,并对这个重大问题感到抱歉。

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值