I just can't decide on which approach to choose to be able to have a hierarchial tree with partially different object types. The application is Asp.Net MVC and I'm using entity framework code first. My hierarchial tree is an information content structure. Each node in the tree can be of either one of my three implemented types.
For now, Table-per-type (TPT) seems to be my best choice of design but what do you think? Any drawbacks with my choice of design? Should the base class have a discriminator field, for example?
To illustrate, below's an pseudo example of my current design.
Regards, Clas Ericson
public abstract class PageObject
{
public int ID { get; set; }
public int? ParentID { get; set; }
public string Title { get; set; }
public virtual PageObject Parent { get; set; }
public virtual ICollection<PageObject> Children { get; set; }
}
[Table("LinkPage")]
public class LinkPage : PageObject
{
public string Url { get; set; }
}
[Table("FramedPage")]
public class FramedPage : LinkPage
{
public int? MinHeight { get; set; }
public int? MinWidth { get; set; }
}
[Table("ContentPage")]
public class ContentPage : PageObject
{
[DataType(DataType.Html)]
[AllowHtml]
public string Content { get; set; }
}
public class InheritanceMappingContext : DbContext
{
public DbSet<PageObject> PageObjects { get; set; }
}