這可能是很簡單的,我會用一個紅色的臉結束......一個或零到許多與代碼首先
class Person {
public Guid Id {get;set;}
public string Name {get;set;}
public Person Manager {get;set;} // The person may or may not have a manager.
public Guid? ManagerId {get;set;} // I need the Guid if the Person has a manager
}
我試圖 modelBuilder.Entity<Person>().HasOptional(e=>e.Manager).WithMany().HasForeignKey(e=>ManagerId)
但是這並沒有什麼好處。
你想做什麼? – saj
難道你不能從Person.Manager.Id獲取管理員ID而不是使用Person.ManagerId?除非在這兩種情況下GUID是不同的,否則我不明白你爲什麼要存儲兩次。 – Onots