基於「雙魚座」同學的三元繼承關聯案例,本文分兩階段實作:
所有代碼基於 NBear 介面式實體定義。

採單表 AllInOne 含所有欄位,FilterMark 區分型別。僅 PrivilegeOwner、User、UserGroup 可查詢,其餘介面僅供概念抽象。
[Table(IsView = true)]
public interface PrivilegeOwner : IEntity {
[PrimaryKey] int Id { get; }
string Name { get; set; }
}
[Table("AllInOne", AdditionalWhere = "FilterMark <= 20", IsView = true)]
public interface User : PrivilegeOwner { }
[Table("AllInOne", AdditionalInsert = "FilterMark = 1", AdditionalWhere = "FilterMark = 1")]
public interface LocalUser : User {
string LoginId { get; set; }
string Password { get; set; }
}
[Table("AllInOne", AdditionalInsert = "FilterMark = 2", AdditionalWhere = "FilterMark = 2")]
public interface AgentUser : User {
string LoginId { get; set; }
}
[Table("AllInOne", AdditionalInsert = "FilterMark = 3", AdditionalWhere = "FilterMark = 3")]
public interface GhostUser : User { }
[Table("AllInOne", AdditionalInsert = "FilterMark = 21", AdditionalWhere = "FilterMark = 21")]
public interface UserGroup : PrivilegeOwner {
string Comment { get; set; }
}
後續將展示具體表映射、擴展表映射,以及介面隔離重構後的對應實作。