這個問題在這里已經有了答案:
PS:我知道某些 DB 屬性可能會得到改進,但我現在不能。
PS2:這不是我的代碼的完整版本,我洗掉了對我的問題無用的物件。
先感謝您
uj5u.com熱心網友回復:
您必須在查詢中添加包含
Context.Persons. Include(i=>i.Works).FirstOrDefault(i=> i.Id==id );
如果您從 Death 中洗掉 [NotMapped],并添加 Death Id
public int DeathId { get; set; }
public virtual Death Death { get; set; }
并修復你的死亡課,我相信一個人只能有一次死亡
public class Death {
[Key]
public string Id {get; set;}
[StringLength(4, MinimumLength = 4)]
public string DeathYear { get; set; }
public virtual Person Person { get; set; }
}
你可以使用這個查詢
Context.Persons.Include(i=>i.Works).Include(i=>i.Death).FirstOrDefault(i=>i.Id==id);
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/356453.html
