C# 在C中映射IS-A关系的正确方法#
让我们想象一个简单的IS-a关系,如以下示例:C# 在C中映射IS-A关系的正确方法#,c#,sql,orm,C#,Sql,Orm,让我们想象一个简单的IS-a关系,如以下示例: create table EntityAbstract( IDEntityAbstract int identity primary key, Name nvarchar(50) not null, ) create table OneOfConcreteEntity( EntityAbstract int, constraint PK_Image primary key (EntityAbstract), constrai
create table EntityAbstract(
IDEntityAbstract int identity primary key,
Name nvarchar(50) not null,
)
create table OneOfConcreteEntity(
EntityAbstract int,
constraint PK_Image primary key (EntityAbstract),
constraint FK_Image foreign key (EntityAbstract) references EntityAbstract(IDEntityAbstract)
)
当我从数据库映射实体时,我应该使它们成为独立的唯一对象,还是应该使具体类从抽象实体扩展而来
e、 g:
最好的选择是什么?考虑到不止一个具体实体和更复杂的实体。有几个实体涉及IS-A关系,通常这正是继承的目的
public class EntityAbstract
{
public int EntityAbstractID { get; set; }
public string Name { get; set; }
public EntityAbstract(int entityID, string name)
{
this.EntityAbstractID = entityID;
this.Name = name;
}
}
public class OneOfConcreatEntity : EntityAbstract
{
public OneOfConcreatEntity(int entityID, string name) : base(entityID, name){ }
}