Entity framework tph mapping property multiple conditions

445 views Asked by At

i'm developing a web application that implements entity framework 6 code first pattern. in my project i've already done table inheritance with TPH, TPT and TPC patterns for some reasons, but now I have a problem like this:

1) I've created a base table table 1 with some properties and some of these are "key" columns to identitfy the inheritance type

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; }
}

I must implement this base table in some properties of independent entities, like this example:

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; }
}

The ideal implementation is that I can use same class(entity) and table for all entitites, and in mapping i would specifiy, for example, column Table1Ref1 will get records with TableName at value 'OtherEntity' and ColumnName at value 'Ref1' and ItemId at entity key value; column Table1Ref2 with same TableName and ItemId and ColumnName at value 'Ref2' etc..

Is it possible to implement this solution?

0

There are 0 answers