views:

107

answers:

0

I have a bunch of domain entities that can be keyword tagged (a Tag is also an entity.)

I want to do a normal many-to-many (Tag -> TagReview <- Review) table relationship but I don't want to have to create a new concrete relationship on both the Entity and Tag every single time I add a new entity.

I was hoping to do a generic based Tag and do this:

// Tag 
public class Tag<T>
{
    public virtual int Id { get; private set; }
    public virtual string Name { get; set; }
    public virtual IList<T> Entities { get; set; }

    public Tag()
    {
        Entities = new List<T>();
    }
}

// Review
public class Review
{
    public virtual string Id { get; private set; }
    public virtual string Title { get; set; }
    public virtual string Content { get; set; }
    public virtual IList<Tag<Review>> Tags { get; set; }

    public Review()
    {
        Tags = new List<Tag<Review>>();
    }
}

Unfortunately I get an exception:

----> System.ArgumentException : Cannot create an instance of FluentNHibernate.Automapping.AutoMapping`1[Example.Entities.Tag`1[T]] because Type.ContainsGenericParameters is true.

I anticipate there will be maybe 5-10 entities so mapping normally would be ok but is there a way to do something like this?