2016-02-13 89 views
1

我指的是在這裏找到的教程:流利的API EF教程錯誤

http://www.entityframeworktutorial.net/code-first/configure-one-to-many-relationship-in-code-first.aspx

鑑於

​​

糾正我,如果我錯了。我覺得這是不對

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是學生的外鍵,而不是標準。

但文章說他們是一樣的。

請讓我知道我是否正確。

謝謝。

回答

0

玩了一遍代碼後明白了。

這兩個流利的API是相同的,不管你是從Student還是Standard來遍歷。

原因是這裏只有一個外鍵,那就是StdId。