views:

177

answers:

0

In Castle Activerecord (on top of NHibernate), is it possible to use class table inheritance globally, and single table inheritance on 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 that all the common "stuff" (like name, description, etc) is in the "model" table, but I can still use STI on the "container" table. Or is this a waste of time and should I go to STI for the whole thing?

Thanks in advance, Jim

related questions