在 Castle Activerecord 中同时使用类表和单表继承?
在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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论