私の問題の解決策を見つけようとしましたが、今までの努力は無駄でした。 :-(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);
}
}
エラーが変更前の発生しましたので、私は
[ConcurrencyCheck]
public int Versao { get; set; }
に
[Timestamp]
public byte[] Versao { get; set; }
からVersao(バージョン)という名前のプロパティを変更しなければならなかったすべてのまず(型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、およびコードの最初のアプローチは可能ですか?そうでない場合、.NETコネクタではなくODBCコネクタに切り替えるとどうなりますか?
ご質問ありがとうございました。
スタックトレースとは何ですか?私はこれがこれではないかと思います:http://entityframework.codeplex.com/workitem/461 – Pawel