Can this mapping be done with (Fluent) NHibernate?

I have an event table whose purpose is to keep track of the actions performed by website users. The action basically modifies or creates a new row in table X. This will allow me to keep a history of all the actions the user takes. Thus, events contain:

  • primary key column
  • text to describe the event (for example: "posted a comment")
  • separator column if needed
  • foreign key column to another table A
  • foreign key column to another table B
  • ....
  • foreign key column to another table N

Only one of the foreign key columns will be set in the row in the "Events" table, all the others will be empty (so they are all NULL). The table behaves like an orientation table to the actual table associated with the event. I don't know if a discriminator is needed since all the information is contained in the foreign key columns. Tables A through N can be anything. Their domain model class can have a common interface if needed (IEventRecordable).

My question is: Is a mapping possible between the Events table and the Event class? Is this especially doable with anhydrous nhibernate? Is it possible to do this without creating many Event derived classes (I don't want to create so many empty subclasses)? The Event class would ideally be as follows:

public class Event
{
    public virtual int Id { get; set; }
    public virtual IEventRecordable ActualEvent { get; set; }
    public virtual string EventDescription { get; set; }
    DateTime EventDateTime { get; set; }
}

      

Many domain class class classes can implement IEventRecordable (which is basically an empty interface). It could be the User table or the BlogComment table ...

thank

+1


source to share


1 answer


If you forget about a few foreign key columns, you can do this <any> mapping .



+2


source







All Articles