Use both Class Table and Single Table inheritance in Castle Activerecord?

In Castle Activerecord (on top of NHibernate), is it possible to use class table inheritance globally and unidirectional inheritance of part of the inheritance tree? I would like to do something like

/// <summary>
/// Base class for models
/// </summary>
[ActiveRecord("model"), JoinedBase]
public abstract class Model: ActiveRecordBase
{
    /// <summary>
    /// Primary Key
    /// </summary>
    [PrimaryKey(PrimaryKeyType.UuidHex, "ROWID", Params = "format=D,separator=-")]
    public virtual string Id { get; set; }

    [Property("name")]
    public string Name { get; set; }

    [Property("description")]
    public string Description{ get; set; }

}

/// <summary>
/// A container
/// </summary>
[ActiveRecord("container")]
public class Container : Model
{
    /// <summary>
    /// Gets the container id
    /// </summary>
    [JoinedKey("container_id")]
    public override string Id
    {
        get { return base.Id; }
        set { base.Id = value; }
    }
}

/// <summary>
/// A glass
/// </summary>
[ActiveRecord("container",
              DiscriminatorColumn = "container_type",
              DiscriminatorValue = "1"
)]
public class Glass : Container
{
}

So, all common β€œthings” (like name, description, etc.) are in the β€œmodel” table, but I can still use the STI in the β€œcontainer” table. Or is it a waste of time and should I go for an STI for all this?

Thanks Jim

+3
source share

Source: https://habr.com/ru/post/1727296/


All Articles