yo2011
yo2011

Reputation: 1021

ServiceStack OrmLite Class Hierarchy in One table

I have a Base abstract Class and two derived classes and i want all of them to be stored in one table(Table per Hierarchy); How can i achieve this in ServiceStack OrmLite or Workaround for this issue.

public abstract class MyBaseClass
{
    public String Name { get; set; }
}

public class MyDerivedClassA : MyBaseClass
{
    public String Name1 { get; set; }
}
public class MyDerivedClassB : MyBaseClass
{
    public String Name2 { get; set; }
}

Upvotes: 0

Views: 236

Answers (1)

mythz
mythz

Reputation: 143409

OrmLite POCO's map 1:1 with their underlying table so all properties would need to be flattened in the base class. If you want you can use [Alias] to have all types look at the same table, i.e:

[Alias("Table")]    
public abstract class MyBaseClass
{
    public String Name { get; set; }
    public String Name1 { get; set; }
    public String Name2 { get; set; }
}

[Alias("Table")]    
public class MyDerivedClassA : MyBaseClass {}

[Alias("Table")]    
public class MyDerivedClassB : MyBaseClass {}

But this is rather pointless. Just map your types as they appear in the database, it's makes it much easier to reason about exactly what's happening.

Upvotes: 1

Related Questions