> I would like to know what the best way to map a collection of child
> objects, that may have different parent types.

I've done something like this recently - a project I've worked on has
a generic "Notes" implementation where Notes can (in theory) be
attached to any class.

The relevant part of our mapping (using Attributes) looks like this:


        /// <summary>
        /// Gets or sets the owner of this note
        /// </summary>
        // Add MetaValue attributes for each entity type that has notes.
        [Any(0, Name = "OwnerEntity", MetaType = "System.String",
IdType = "System.Int32")]
        [MetaValue(1, Class = "Rbnz.Fsis.Entities.OrganisationEntity,
Rbnz.Fsis.Entities", Value = "ORG")]
        [MetaValue(2, Class = "Rbnz.Fsis.Entities.OutputTsDefEntity,
Rbnz.Fsis.Entities", Value = "OTD")]
        [MetaValue(3, Class = "Rbnz.Fsis.Entities.SurveyReturnEntity,
Rbnz.Fsis.Entities", Value = "SRN")]
        [MetaValue(4, Class =
"Rbnz.Fsis.Entities.SurveyCollectionPeriodEntity, Rbnz.Fsis.Entities",
Value = "SCP")]
        [Column(5, Name = "OwnerType")]
        [Column(6, Name = "OwnerKey")]
        public virtual IBusinessEntity OwnerEntity { get; set; }

To break this down ...

... there are two columns on the Notes table, one specifying the
*kind* of parent, the other the *dbKey* of the parent
... the overall association is an <any>
... we use MetaValue mappings to relate the codes used for kind of
parent to actual classes

This works well, but there are some drawbacks. Most significantly, you
can't query across this association with HQL or Criteria queries.

Hope this helps,
Bevan.

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