Hello guys!
I have some trouble with EF6 using MySql database and a many to many relation with an association table.
So i have these entities :
- [Table("user")]
- public partial class user
- {
- public user()
- {
- }
- public int id { get; set; }
- [Required]
- [StringLength(255)]
- public string first_name { get; set; }
- [Required]
- [StringLength(255)]
- public string last_name { get; set; }
- [Required]
- [StringLength(255)]
- public string email { get; set; }
- [Required]
- [StringLength(255)]
- public string hash { get; set; }
- public virtual ICollection<role> Roles { get; set; }
- [Table("role")]
- public partial class role
- {
- public role()
- {
- }
- public int id { get; set; }
- [Required]
- [StringLength(255)]
- public string title { get; set; }
- public virtual ICollection<user> Users { get; set; }
- }
And i start like that : i enable migrations, its working perfectly. I add first migration, its working perfectly.
But when i try to update-database i have this error :
System.FormatException : Input string was not in a correct format.
But i dont know why, because when i delete the collection in the 2 entities it work perfectly..
There is my context :
- public class TestContext : DbContext
- {
- public TestContext() : base("name=TestContext")
- {
- Database.SetInitializer<TestContext>(new DropCreateDatabaseIfModelChanges<TestContext>());
- }
- public virtual DbSet<role> Roles { get; set; }
- public virtual DbSet<user> Users { get; set; }
- protected override void OnModelCreating(DbModelBuilder modelBuilder)
- {
- modelBuilder.Entity<user>()
- .HasMany(e => e.Roles)
- .WithMany(e => e.Users)
- .Map(m => m.ToTable("role_user", "test"));
- }
Someone have idea ?
Thank you!