【发布时间】:2019-03-26 18:32:17
【问题描述】:
我在与 Entity-Framework V6 上的关联表的多对多关系方面遇到了一些问题。 我使用 MySql 作为数据库,但总是遇到同样的错误。
我在 youtube、stackoverflow、entityframeworktutorial、entityframework 文档上尝试了很多教程,但是当我尝试建立多对多关系时,我总是遇到同样的错误。
我使用 .NET 4.7.2 Framework、MySQL 5.7.24、Entity Framework 6、MySql Connector 8.0.15、MySql.Data 6.10.8.0、MySQl.Data.Entity.EF6 6.10.8.0
这是我的第一个实体:
[Table("course")]
public class Course
{
[Key]
[Column("idcourse")]
public int Id { get; set; }
[Column("name")]
public string Name { get; set; }
public virtual ICollection<StudentCourse> Students { get; set; }
}
我的第二个实体:
[Table("student")]
public class Student
{
[Key]
[Column("idstudent")]
public int Id { get; set; }
[Column("name")]
public string Name { get; set; }
// Important - virtual
public virtual ICollection<StudentCourse> Courses { get; set; }
}
还有我的关联表:
[Table("student_course")]
public class StudentCourse
{
[Key]
[Column("idstudent_course")]
public int Id { get; set; }
[Column("idstudent")]
[ForeignKey("Student")]
public int StudentId { get; set; }
[Column("idcourse")]
[ForeignKey("Course")]
public int CourseId { get; set; }
[Column("coursescore")]
public int CourseScore { get; set; }
public virtual Student Student { get; set; }
public virtual Course Course { get; set; }
}
当我启动 add-migration [name] 时没问题。但是当我尝试更新数据库时,Visual Studio 给我这个错误:输入字符串格式不正确。 (翻译因为我是法语,而我的 IDE 是法语)
有人有解决方案吗? 谢谢!
【问题讨论】:
-
有关异常的更多信息?可能是内部异常,堆栈跟踪或任何 sql 查询部分?这可能会有所帮助:stackoverflow.com/questions/49552550/…
标签: entity-framework entity-framework-6