0

我正在开发一个实现实体框架 6 代码优先模式的 Web 应用程序。在我的项目中,由于某些原因,我已经使用 TPH、TPT 和 TPC 模式完成了表继承,但现在我遇到了这样的问题:

1)我创建了一个带有一些属性的基表表 1,其中一些是用于识别继承类型的“关键”列

public class Table1 : BaseEntity
{
    public Table1()
        : base()
    {

    }

    public int Table1Id { get; set; }
    public int ItemId { get; set; }
    public string TableName { get; set; }
    public string ColumnName { get; set; }
    public string Value { get; set; }
}

我必须在独立实体的一些属性中实现这个基表,比如这个例子:

public class OtherEntity {

    public OtherEntity()
        : base()
    {
        ...
    }

    ...
    public virtual ICollection<Table1> Table1Ref1 { get; set; }
    public virtual ICollection<Table1> Table1Ref2 { get; set; }
    public virtual ICollection<Table1> Table1Ref3 { get; set; }
}

public class OtherEntity1 {

    public OtherEntity1()
        : base()
    {
        ...
    }

    ...
    public virtual ICollection<Table1> Table1Ref1 { get; set; }
    public virtual ICollection<Table1> Table1Ref2 { get; set; }
    public virtual ICollection<Table1> Table1Ref3 { get; set; }
}

理想的实现是我可以为所有实体使用相同的类(实体)和表,并且在映射中我会指定,例如,Table1Ref1 列将获取 TableName 值为“OtherEntity”和 ColumnName 值为“Ref1”和 ItemId 的记录在实体键值处;列 Table1Ref2 具有相同的 TableName 和 ItemId 和 ColumnName 在值 'Ref2' 等..

是否可以实施此解决方案?

4

0 回答 0