Entity Framework 4 - TPH Inheritance in CTP5 Functions (Code First) with "IS NULL" Discriminator

Hey guys, I'm trying to create a TPH mapping in a hierarchy where the discriminatory sentence is the classic case of "IS NOT NULL" / "NULL".

Here is an example, a wise database:

CREATE TABLE info.EducationTypes
(
   ID INT NOT NULL PRIMARY KEY,
   Name NVARCHAR(64) NOT NULL,
   FKParentID INT NULL REFERENCES info.EducationTypes(ID)
)

the idea is to have a class hierarchy, such as the following:

public abstract class EducationType
{
    public int ID { get; set; }
    public string Name { get; set; }
}

public class MainEducationType : EducationType
{
    public IEnumerable<SubEducationType> SubTypes { get; set; }
}

public class SubEducationType : EducationType
{
    public MainEducationType MainType { get; set; }
}

This scheme works for me in the classic xml model, but I really can’t find a way to make it work using the first code approach. This is what I tried ...

var educationType = modelBuilder.Entity<EducationType>();
educationType.Map<MainEducationType>(m => m.Requires("FKParentID").HasValue(null));
educationType.Map<SubEducationType>(m => m.Requires("FKParentID"));

Do you have any suggestions?

+1
source share
1 answer

, TPH CTP5. EF , . , , RTM.

+3

All Articles