开发者

Entity Framework 4 - TPH Inheritance in Features CTP5 (code first) with "IS NULL" discriminator

Hey guys, I'm trying to create a TPH mapping on a hierarchy where the discriminating clause is the classical "IS NOT NULL" / "IS NULL" case.

Here is the example, database wise:

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 like the following one:

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 { ge开发者_StackOverflow社区t; set; }
}

I got this schema "working" in the classic xml model, but I really can't find a way to get it working by using the code first 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 suggestion?


Unfortunately, having a null value for the discriminator column in TPH mapping is not currently supported in CTP5. This is confirmed by EF team on here and also here. They are looking at it to see if they can make it work for the RTM though.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜