0
我有以下幾點:實體框架代碼優先:一對一的關係不產生外鍵
public abstract class EntityBase
{
[Key]
public int Id { get; set; }
public DateTime? CreatedTime { get; set; }
public DateTime? ModifiedTime { get; set; }
}
public class AnalysisFile : EntityBase
{
public AnalysisFile()
{
DateAdded = DateTime.Now;
}
public string SourceFolder { get; set; }
public string Filename { get; set; }
public DateTime DateAdded { get; set; }
public long FileSize { get; set; }
public Document Document { get; set; }
}
public class Document : EntityBase
{
public Document()
{
Publish = true;
}
public string Name { get; set; }
public int AreaId { get; set; }
public int SchoolId { get; set; }
public int Year { get; set; }
public long FileSize { get; set; }
public AnalysisFile AnalysisFile { get; set; }
public School School { get; set; }
public Area Area { get; set; }
public bool Publish { get; set; }
}
modelBuilder.Entity<Document>().HasRequired(x => x.AnalysisFile);
modelBuilder.Entity<AnalysisFile>().HasOptional(x => x.Document);
我的問題是,EF不會出現創造AnalysisFile和文檔之間的關係的外鍵,很我在這裏錯過了什麼,或者這是預期的行爲?
我也嘗試在兩個類上創建AnalysisFileId和DocumentId屬性,但是當我這樣做時,它們不會使用任何ID填充。
另一個問題也是:我如何確保Document對AnalysisFile進行級聯刪除?
我確實想知道共享主鍵,非常感謝:-) – Mantorok