2013-02-22 5 views
5

Używam Entity Framework 5 kod najpierw i mam następujący model:Jak mapę określającą relację w Entity Framework 5 Kod Podmiotu pierwsze dziecko z wielu wzajemnie wykluczających podmiotów dominujących

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;} 
} 

Umiem map relacja identyfikująca, w której jednostka podrzędna ma jednego rodzica. Ale chciałbym odwzorować obiekt strony, aby miał powiązanie identyfikacyjne dla każdego z rodziców.

Ponadto, relacje macierzyste wzajemnie się wykluczają. Określona strona będzie należeć do DocumentTemplate lub Document, a nie do obu.

Czy takie mapowanie jest możliwe w Entity Framework 5?

Nie chcę tworzyć oddzielnych elementów dla strony, ponieważ będą one zasadniczo takie same, z wyjątkiem relacji nadrzędnej.

TIA.

Odpowiedz

0

Nie sądzę, można mieć wiele rodziców, ale chciałbym wziąć pod uwagę następujące opcje:
(Każdy dokument należy do jakiegoś-szablonu, tylko szablony mogą mieć stron)

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;} 
} 
0

to będzie działać dla Ciebie:

class Page 
{ 
    public int Id {get;set;} 
    public string Text {get;set;} 

    public int? DocumentId { get; set; } // non-mandatory relationship to Document 
    public int? DocumentTemplateId { get; set; } // non-mandatory relationship to DocumentTemplate 

    // ... navigation properties 
} 
Powiązane problemy