I am attempting to setup a multiplicity aggregation but not sure how I would accomplish this in the mappings.
Consider the following entities
Code:
public class Document : IContentItem
{
private ContentItemBehavior _contentItemBehavior;
}
public class Image : IContentItem
{
private ContentItemBehavior _contentItemBehavior;
}
public class ContentItemBehavior
{
private IList<Tag> _tags;
}
ContentItemBehavior encapsulates common behavior of tagging, such as adding a tag, removing a tag and housing the collection of tags for the IContentItem.
The problem I am having is how to map the IList<Tag> collection within the Document and Image entities. Would I map the collection as the following:
Code:
<!-- Document mapping file -->
<bag name="ContentItemBehavior.Tags" table="ContentItem_Tag" cascade="all">
<key column="ContentItemId"/>
<many-to-many column="TagId"
class="Tag"/>
</bag>
Also, the collection would be Bidirectional so on that note, in the Tag mapping file can I refer to the entity by the interface, or do I have to use the concrete type on the other end of the collection? like so:
Code:
<bag name="ContentItems" table="ContentItem_Tag" cascade="all">
<key column="TagId"/>
<many-to-many column="ContentItemId"
class="IContentItem"/>
</bag>
I'm not sure if I can use interfaces to reference entities like that. If not, how would I accomplish this? I am trying to favor aggregation over inheritance. I suppose I would have to map ContentItemBehavior?
Thank you!
Sean