2010-08-10 6 views
3

Je cours commeFluent NHibernate regroupant plusieurs lignes à la propriété de collection

public class Content 
{ 
    // ... 
    public virtual IList<Detail> { get; set; } 
} 
public class Detail 
{ 
    // ... 
    public virtual Content Content { get; set; } 
    public virtual string Name { get; set; } 
} 
public class TagDetail : Detail 
{ 
    public virtual Tag Value { get; set; } 
} 
public class TagCollectionDetail : Detail 
{ 
    public virtual IList<Tag> Value{ get; set; } 
} 

et je voudrais corréler ces détails à la table

Details -table 
contentId name type   tagId 
1   Tag  Tag    2 
2   Tags TagCollection 1 
2   Tags TagCollection 3 
2   Tags TagCollection 6 

Est-il possible de regrouper plusieurs lignes à un objet avec NHibernate (et comment)? Je sais que c'est une mauvaise chose de répéter des informations (Detail.Name, Detail.Type) comme ça, mais la recherche serait beaucoup plus facile.

Ou dois-je le mapper en deux tables?

Details -table 
contentId name type   tagId 
1   Tag  Tag    2 
2   Tags TagCollection 

DetailsCollection -table 
detailId tagId 
2   1 
2   3 
2   6 

Répondre

0

Je modélise cela comme suit:

Detail (table) 
    - DetailId (col), PK 
    - ContentId (col), FK to Content table 
    - Name (col) 

Tag (table) 
    - TagId, PK 
    - Other tag columns 

TagDetail (table), only 1 row per Detail 
    - TagDetailId (col), PK 
    - DetailId (col), FK to Detail table 
    - TagId, FK to Tag table 

TagCollectionDetail (table), there would be many rows of this per Detail 
    - TagCollectionDetailId, PK 
    - DetailId (col), FK to Detail table 
    - TagId, FK to Tag table 

PK = clé primaire, FK = clé étrangère. Je définirais ces colonnes à un nombre/type entier, qui est auto-incrémenté. NHibernate ne fonctionne pas très bien (ou pas du tout) avec des tables sans clé primaire.

En y réfléchissant encore plus, je ne comprends pas pourquoi vous avez TagDetail et TagCollectionDetail. TagDetail est un cas particulier de TagCollectionDetail, où il n'y a qu'un seul tag. Je pense que vous pouvez vous débarrasser de TagDetail.

Questions connexes