Search code examples
c#.netormlite-servicestack

ServiceStack.OrmLite inheritance mapping


Does ServiceStack.OrmLite support inheritance mapping?

Like DevExpress XPO: Inheritance Mapping or nHibernate Inheritance.

For example (c#):

public abstract class EventBase
{
   public string Name { get;set; }
}
public class NormalEvent: EventBase
{
   public string A { get;set; }
}
public class SuperDuppaEvent:EventBase
{
   public string B { get;set; }
}

In database exist one table 'EventBase' with all Columns/Properties from 'NormalEvent', 'SuperDuppaEvent' and from 'EventBase' too.

In the documentation exist the 'AliasAttribute' but it doesn't work.


Solution

  • No OrmLite does not support inheritance mapping. It's a core expectation in OrmLite that each POCO maps 1:1 with the RDBMS table it represents. So by default each of your classes will map to an RDBMS table with the same name:

    • NormalEvent > NormalEvent table
    • SuperDuppaEvent > SuperDuppaEvent table

    If you want different behavior you'd need to map the POCO classes 1:1 with how you want it laid out in the database, e.g:

    class NormalEvent
    {
        public string A { get; set; }
        public int EventBaseId { get; set; }
    }