在 Castle Activerecord 中同时使用类表和单表继承?

发布于 2024-08-17 11:21:08 字数 1244 浏览 2 评论 0原文

在Castle Activerecord(在NHibernate之上)中,是否可以全局使用类表继承,并在继承树的一部分上使用单表继承?我想做类似的事情

/// <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
{
}

,以便所有常见的“东西”(如名称、描述等)都在“模型”表中,但我仍然可以在“容器”表上使用 STI。或者这是浪费时间,我应该去 STI 完成整个事情吗?

提前致谢,吉姆

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文