Rou*_*len 5 c# relationship entity-framework-5
我正在使用Entity Framework 5 Code First,我有以下模型:
class Document
{
public int Id {get;set;}
public String Name {get;set;}
public IList<Page> Pages {get;set;}
}
class DocumentTemplate
{
public int Id {get;set;}
public String Description {get;set;}
public String Name {get;set;}
public IList<Page> Pages {get;set;}
}
class Page
{
public int Id {get;set;}
public string Text {get;set;}
}
Run Code Online (Sandbox Code Playgroud)
我知道如何映射子实体有1个父项的识别关系.但我想映射Page实体,以便它具有每个父级的标识关系.
此外,父关系是互斥的.特定页面将属于DocumentTemplate或Document,而不是两者.
实体框架5中是否可以进行这种映射?
我不想为Page创建单独的实体,因为它们基本上是相同的,除了父关系.
TIA.
我不认为你可以有多个父母,但我会考虑以下选项:(
任何文档属于某个模板,只有模板可以有页面)
class Document
{
public int Id {get;set;}
public String Name {get;set;}
public DocumentTemplate DocumentTemplate{get;set;}
}
class DocumentTemplate
{
public int Id {get;set;}
public String Description {get;set;}
public String Name {get;set;}
public IList<Page> Pages {get;set;}
}
class Page
{
public int Id {get;set;}
public string Text {get;set;}
}
Run Code Online (Sandbox Code Playgroud)