You can use many-to-many relationships (one table per Set), or map Comment
as a component.

   Diego


On Wed, Jun 23, 2010 at 19:23, Ian <[email protected]> wrote:

> Hi,
>
> I would like to know what the best way to map a collection of child
> objects, that may have different parent types.
>
> For example, say I have a generic Comment class, which I want to reuse
> to track comments associated with other entities such as Project,
> Organisation, Document, etc...:
>
> public class Comment
> {
>    public string Comment { get; set; }
>    public string User { get; set; }
>    public DateTime CommentDate { get; set; }
>    ....
> }
>
> public class Project
> {
>    ....
>    public ISet<Comment> Comments { get; set; }
> }
>
> public class Organisation
> {
>    ....
>    public ISet<Comment> Comments { get; set; }
> }
>
> If I use a one-to-many relationship for the Comments property in both
> Project and Organisation mapping files I will obviously run into the
> problem of the Comment records in the DB not knowing whether its
> parent/owner is a Project or an Organisation.
>
> There should therefore be something allowing NHibernate to distinguish
> what type of parent the comment record belongs to so it can load the
> relevant comment records when loading a Project or Organisation.
>
> Is there a good way of supporting this in NHibernate? It seems
> Hibernate supports the notion of 'Top-level Collections' (http://
> www.xylax.net/hibernate/toplevel.html) to deal with exactly this type
> of scenario, but I have found nothing in NHibernate. (It is possible
> that it has been depracated in Hibernate as I also found a post
> questionning whether this should be supported because it forces you to
> break DB referential integrity as you no longer have FKs between child
> and various parent records).
>
> Many thanks,
> Ian
>
> --
> You received this message because you are subscribed to the Google Groups
> "nhusers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<nhusers%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/nhusers?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to