Map NHibernate entity to multiple tables based on parent
Posted
by Programming Hero
on Stack Overflow
See other posts from Stack Overflow
or by Programming Hero
Published on 2010-03-15T16:59:20Z
Indexed on
2010/03/15
17:19 UTC
Read the original article
Hit count: 626
nhibernate
|fluent-nhibernate
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.
© Stack Overflow or respective owner