Hi Mike, Presumably you also added a property/column on the child indicating what type of parent it belongs to?
Thanks, Ian On Jun 24, 5:23 am, Mike <[email protected]> wrote: > I am running into this same exact issue. I'm handling it by only > mapping the child to the parent, but not mapping the parent to the > child. Not preferred, I understand, but it works. Please keep us > posted as to your final solution. > > On Jun 23, 5:23 pm, 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]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
