本文介绍了实体框架4-TPH在特征C中的继承CTP5(代码优先),具有“IS NULL”鉴别器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! Hey guys,我试图在层次结构上创建一个TPH映射,其中歧视子句是经典的IS NOT NULL/IS NULL情况。 这里是示例,数据库明智: CREATE TABLE info.EducationTypes $ b ID INT NOT NULL PRIMARY KEY,名称NVARCHAR(64)NOT NULL, FKParentID INT NULL REFERENCES info.EducationTypes(ID)) 这个想法是有类层次结构,如下所示: public abstract class EducationType { public int ID {get;组; } public string Name {get;组; } } public class MainEducationType:EducationType { public IEnumerable< SubEducationType> SubTypes {get;组; } } public class SubEducationType:EducationType { public MainEducationType MainType {get;组; } } 我在经典的xml模型中得到了这个模式working真的找不到一个方法来使它的工作通过使用代码第一种方法。这是我尝试... var educationType = modelBuilder.Entity< EducationType>(); educationType.Map< MainEducationType>(m => m.Requires(FKParentID)。HasValue(null)); educationType.Map< SubEducationType>(m => m.Requires(FKParentID));你有什么建议吗? 解决方案不幸的是,目前在CTP5中不支持TPH映射中的鉴别器列为空值。这是由EF团队在此处以及此处。他们正在看它,看看他们是否可以使它的RTM工作。 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 { get; 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. 这篇关于实体框架4-TPH在特征C中的继承CTP5(代码优先),具有“IS NULL”鉴别器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-30 01:52