views:

154

answers:

1

I'm creating a domain model where entities often (but not always) have a member of type ActionLog.

ActionLog is a simple class which allows for an audit trail of actions being performed on an instance. Each action is recorded as an ActionLogEntry instance.

ActionLog is implemented (approximately) as follows:

public class ActionLog
{   
    public IEnumerable<ActionLogEntry> Entries
    {
        get { return EntriesCollection; }
    }

    protected ICollection<ActionLogEntry> EntriesCollection { get; set; }

    public void AddAction(string action)
    {
        // Append to entries collection.
    }
}

What I would like is to re-use this class amongst my entities and have the entries map to different tables based on which class they are logged against. For example:

public class Customer
{
    public ActionLog Actions { get; protected set; }
}

public class Order
{
    public ActionLog Actions { get; protected set; }
}

This design is suitable for me in the application, however I can't see a clear way to map this scenario to a database with NHibernate.

I typically use Fluent NHibernate for my configuration, but I'm happy to accept answers in more general HBM xml.

A: 

youu can use join to map it to more than table

Ahmed