我试图为我的问题找到解决方案,但直到现在我的努力都是徒劳的。 :-(MySQL 5.5 + .NET连接器+实体框架+迁移= 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<Usuario> Usuarios { get; set; }
public virtual ICollection<Permissao> 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<Perfil> 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,Entity Framework和代码优先的方法?如果没有,切换到ODBC连接器而不是.NET连接器的后果是什么?
在此先感谢您,并对此感到抱歉。
什么是堆栈跟踪?我不知道这是不是这个:http://entityframework.codeplex.com/workitem/461 – Pawel