代码之家  ›  专栏  ›  技术社区  ›  Rune

在实体框架4的TPH继承场景中使用导航属性作为鉴别器

  •  0
  • Rune  · 技术社区  · 15 年前

    我有以下实体:

    Person:
      Id (int)
      Name (nvarchar)
      PlaneId (int)
      CarId (int)
    
    Car:
      Id (int)
      Name (nvarchar)
    
    Plane:
      Id (int)
      Name (nvarchar)
    

    PlaneId CarId 贝格恩·FKs。我在数据库中有相应的表,并且可以使用VS2010 EF向导创建概念模型。这个 Person 实体有两个导航属性, Car Plane

    现在我想从Person派生出两种类型:

    Pilot (condition: PlaneId is not null)
    Driver (condition: CarId is not null)
    

    所以,我添加实体Pilot,告诉它映射到Person并添加条件 PlaneId is not null . 此时,visualstudio(或者我猜是edmgen)抱怨 Person.PlaneId with 'IsNull=false' condition must be mapped .

    我的下一步是什么?我试过各种方法,但似乎没能奏效。任何洞察力都将不胜感激。

    1 回复  |  直到 15 年前
        1
  •  2
  •   Craig Stuntz    15 年前