重复字段定义,不需为这样的接口定义独立的表。
代码5
[Table(IsView=true)]
public interface IdentableEntity : IEntity
{
[PrimaryKey]
int Id { get; }
string Name { get; set; }
}
[Table(IsView=true)]
public interface Loginable : IEntity
{
string LoginId { get; set; }
}
[Table(IsView=true)]
public interface PasswordLoginable : Loginable
{
string Password { get; set; }
}
[Table(IsView = true)]
public interface PrivilegeAssignable
{
int PrivilegeOwnerId { get; set; }
}
[Table("User")]
public interface User : IdentableEntity, PrivilegeAssignable
{
}
[Table("LocalUser")]
public interface LocalUser : User, PasswordLoginable
{
}
[Table("AgentUser")]
public interface AgentUser : User, Loginable
{
}
[Table("GhostUser")]
public interface GhostUser : User
{
}
[Table("UserGroup")]
public interface UserGroup : IdentableEntity, PrivilegeAssignable
{
string Comment { get; set; }
}
4.3 一实体一扩展表
代码6
[Table(IsView=true)]
public interface IdentableEntity : IEntity
{
[PrimaryKey]
int Id { get; }
string Name { get; set; }
}
[Table(IsView=true)]
public interface Loginable : IEntity
{
string LoginId { get; set; }
}
[Table(IsView=true)]
public interface PasswordLoginable : Loginable
{
string Password { get; set; }
}
[Table(IsView = true)]
public interface PrivilegeAssignable
{
int PrivilegeOwnerId { get; set; }
}
[Table("User")]
public interface UserExtended : IdentableEntity, PrivilegeAssignable
{
[PrimaryKey]
new int Id { get; }
}
[Table("User", IsView=true)]
public interface User : UserExtended
{
}
[Table("LocalUser")]
public interface LocalUserExtended : PasswordLoginable
{
[PrimaryKey]
int Id { get; }
}
[Table("select * from LocalUser inner join User on LocalUser.Id = User.Id", IsView=true)]
public interface LocalUser : LocalUserExtended, User
{
[PrimaryKey]
new int Id { get; }
}
[Table("AgentUser")]
public interface AgentUserExtended : Loginable
{
[PrimaryKey]
int Id { get; }
}
[Table("select * from AgentUser inner join User on AgentUser.Id = User.Id", IsView = true)]
public interface AgentUser : AgentUserExtended, User
{
}
[Table("GhostUser")]
public interface GhostUserExtended : IEntity
{
[PrimaryKey]
int Id { get; }
}
[Table("select * from GhostUser inner join User on GhostUser.Id = User.Id", IsView = true)]
public interface GhostUser : GhostUserExtended, User
{
}
[Table("UserGroup")]
public interface UserGroupExtended : IdentableEntity, PrivilegeAssignable
{
[PrimaryKey]
new int Id { get; }
string Comment { get; set; }
}
[Table("UserGroup", IsView=true)]
public interface UserGroup : UserGroupExtended
{
}
5. 使用映射的实体
对于以上各种方案定义的实体,我们都可以使用NBear.Data.Gateway和NBear.Data.ActiveEntity类进行查询和更新。详细信息请参考NBear中文用户手册。
另外,注意,所有代码示例中的select *在实际使用环境请用字段名列表代替,以避免可能的数据表字段名重名错误。 |