Mapping with extendend class

87 Views Asked by At

I'm using NHibernate with ConfORM to map my domain entities.

Assuming the following classes:

public class Event {
    public virtual Guid Id { get; set; }
    public virtual string Title { get; set; }
    public virtual bool Active { get; set; }
}

public class EventA : Event {
    public virtual string PropertyA { get; set; }
}

public class EventB : Event {
    public virtual string PropertyB { get; set; }
}

Diagram

I need not repeat NHibernate tables fields in derived classes, but uses the base class, as in the diagram.

My ConfORM setup :

var domainAssembly = typeof(Event).Assembly;
var domainEntities = from t in domainAssembly.GetTypes() where t==typeof(Event) select t;
var orm = new ObjectRelationalMapper();
orm.Patterns.Sets.Add(new UseSetWhenGenericCollectionPattern());
orm.Patterns.PoidStrategies.Add(new ConfOrm.Patterns.IdentityPoidPattern());
orm.TablePerConcreteClass(domainEntities);
var patternsAppliers = new CoolPatternsAppliersHolder(orm);
var mapper = new Mapper(orm, patternsAppliers);
[...]

Any ideas on how to approach the problem could?

1

There are 1 best solutions below

0
On

exchange orm.TablePerConcreteClass(domainEntities); with orm.TablePerClass(domainEntities); which will create

Event
-----
PK | Id

EventA
-----
PK,FK | EventId

because a seperate Id column in EventA is not nessesary