0
我有以下3個表:EF4 - 外鍵指向多個表
public class Project
{
// other fields...
public virtual ICollection<Attachment> Attachments { get; set; }
}
public class Experiment
{
// other fields...
public virtual ICollection<Attachment> Attachments { get; set; }
}
public class Attachment
{
// ...
}
如果我創建這個結構,EF將創建表附件有兩列:專案編號和ExperimentId 。
如何告知EF我的關係實驗 - >附件和項目 - >附件必須「共享」附件上的相同密鑰?
喜歡的東西:
public class Attachment
{
// other fields...
// can be a Guid from either Experiment or Project
public Guid BelongingModelId { get; set; }
// I will set this manually in order to know from which table the Guid is coming
public String BelongingModelType { get; set; }
}
可以做這樣的事情?
我試過在DbContext/OnModelCreating中,但是我沒有找到解決方案。
感謝, 圭多