我正在使用實體框架先學習代碼。在問題出現之前,我有:更新模型後更新數據庫無法正常工作
public class Book
{
[Key]
public int Id { get; set; }
[Required]
public string Title { get; set; }
[Display(Name = "Publication Name")]
public DateTime PublicationDate { get; set; }
[Required]
public float Edition { get; set; } // We might have a 2.5 edition. Rare but happens
public Author Author { get; set; }
}
我也有幾個控制器和視圖。我向數據庫添加了一條記錄,以測試CRUD是否有效,然後將其刪除。
然後我加[Required]
到Author Author
並試圖運行遷移,並且update-database
。它只是喊我說:
Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "assignment1.Migrations.Addrequiredtoauthorinbookcs.resources" was correctly embedded or linked into assembly "assignment1" at compile time, or that all the satellite assemblies required are loadable and fully signed.
任何想法我做錯了什麼,以及如何解決它?
更改爲'public virtual Author Author {get;組; }'以避免循環引用。 –
什麼是虛擬的? – alex3wielki
在實體框架中,Virtual是一個用於激活延遲加載的關鍵字。 –