【发布时间】:2016-05-24 12:16:48
【问题描述】:
我指的是这里的教程:
给定
public class Student
{
public int StudentId { get; set; }
public string StudentName { get; set; }
//StdId is not following code first conventions name
public int StdId { get; set; }
public virtual Standard Standard { get; set; }
}
public class Standard
{
public int StandardId { get; set; }
public string Description { get; set; }
public virtual ICollection<Student> Students { get; set; }
}
如果我错了,请纠正我。我认为这是错误的
modelBuilder.Entity<Standard>()
.HasMany<Student>(s => s.Students)
.WithRequired(s => s.Standard)
.HasForeignKey(s => s.StdId);
这是正确的
modelBuilder.Entity<Student>()
.HasRequired<Standard>(s => s.Standard)
.WithMany(s => s.Students)
.HasForeignKey(s => s.StdId);
因为 StdId 是 Student 的外键,而不是 Standard。
但是文章说它们是一样的。
如果我是对的,请告诉我。
谢谢。
【问题讨论】:
标签: c# entity-framework-6 extension-methods ef-fluent-api