EF 4.1 TPT наследует причины «Зависимое свойство в ReferentialConstraint сопоставлено сгенерированным хранилищем столбцом» - PullRequest
0 голосов
/ 14 ноября 2011

Добрый день!

У нас есть TPT-наследование в нашей модели данных EF, основанное на наборе представлений и хранимых процедур в базе данных. Существует базовая сущность Tag , которая НЕ является абстрактной и имеет первичный ключ TtrId, и унаследованная сущность FinancialGoal . Тег сущность, основанная на представлении vwTagTree, FinancialGoal основанная на представлении vwGoals. Оба представления имеют поле TtrId, реализующее отношение один к одному. Каждый объект связан с другими модельными объектами. Поле TtrId объекта Tag имеет атрибут StoreGeneratedPattern = Identity, но оно не участвует ни в какой ассоциации в качестве зависимого поля.

Однако мы получаем ошибку " Зависимое свойство в ReferentialConstraint отображается в столбец, созданный магазином. Столбец: 'TtrId'. " при попытке добавить объект FinancialGoal, Выбор в порядке, обновление в порядке, вставка Tag объекта в порядке, но вставка FinancialGoal объекта вызывает упомянутую ошибку.

Вот часть схемы модели EF:

К сожалению, я не могу опубликовать скриншот из-за низкой репутации, поэтому вот CSDL часть определения EDMX:

   <EntityType Name="Tag" Abstract="false">
      <Key>
        <PropertyRef Name="TtrId" />
      </Key>
      <Property Type="Int32" Name="TtrId" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
      <Property Type="Int32" Name="TtrParentId" />
      <Property Type="String" Name="TtrName" Nullable="false" MaxLength="256" FixedLength="false" Unicode="false" />
      <Property Type="Int32" Name="CusId" />
      <Property Type="Boolean" Name="TtrIsExpense" />
      <Property Type="String" Name="TtrTypeFlag" Nullable="false" FixedLength="true" MaxLength="1" Unicode="false" />
      <Property Type="Int32" Name="UsrChangeId" />
      <NavigationProperty Name="NavChildTags" Relationship="IbModel.TagTag" FromRole="TagParent" ToRole="TagChild" />
      <NavigationProperty Name="NavParentTag" Relationship="IbModel.TagTag" FromRole="TagChild" ToRole="TagParent" />
      <NavigationProperty Name="NavCustomer" Relationship="IbModel.CustomerTag" FromRole="Tag" ToRole="Customer" />
      <NavigationProperty Name="NavTagOverrides" Relationship="IbModel.TagTagOverride" FromRole="Tag" ToRole="TagOverride" />
    </EntityType>
    <EntityType Name="TagOverride">
      <Key>
        <PropertyRef Name="TtrId" />
        <PropertyRef Name="CusId" />
      </Key>
      <Property Type="Int32" Name="TtrId" Nullable="false" />
      <Property Type="Int32" Name="CusId" Nullable="false" />
      <Property Type="String" Name="TtoCustomName" Nullable="false" MaxLength="256" FixedLength="false" Unicode="false" />
      <Property Type="Int32" Name="UsrChangeId" />
      <NavigationProperty Name="NavCustomer" Relationship="IbModel.CustomerTagOverride" FromRole="TagOverride" ToRole="Customer" />
      <NavigationProperty Name="NavTag" Relationship="IbModel.TagTagOverride" FromRole="TagOverride" ToRole="Tag" />
    </EntityType>
    <Association Name="TagTag">
      <End Type="IbModel.Tag" Role="TagParent" Multiplicity="0..1" />
      <End Type="IbModel.Tag" Role="TagChild" Multiplicity="*" />
      <ReferentialConstraint>
        <Principal Role="TagParent">
          <PropertyRef Name="TtrId" />
        </Principal>
        <Dependent Role="TagChild">
          <PropertyRef Name="TtrParentId" />
        </Dependent>
      </ReferentialConstraint>
    </Association>
    <Association Name="CustomerTagOverride">
      <End Type="IbModel.Customer" Role="Customer" Multiplicity="1" />
      <End Type="IbModel.TagOverride" Role="TagOverride" Multiplicity="*" />
      <ReferentialConstraint>
        <Principal Role="Customer">
          <PropertyRef Name="CusId" />
        </Principal>
        <Dependent Role="TagOverride">
          <PropertyRef Name="CusId" />
        </Dependent>
      </ReferentialConstraint>
    </Association>
    <Association Name="CustomerTag">
      <End Type="IbModel.Customer" Role="Customer" Multiplicity="0..1" />
      <End Type="IbModel.Tag" Role="Tag" Multiplicity="*" />
      <ReferentialConstraint>
        <Principal Role="Customer">
          <PropertyRef Name="CusId" />
        </Principal>
        <Dependent Role="Tag">
          <PropertyRef Name="CusId" />
        </Dependent>
      </ReferentialConstraint>
    </Association>
    <EntityType Name="FinancialGoal" BaseType="IbModel.Tag">
      <Property Type="Int32" Name="RefTypeId" Nullable="false" />
      <Property Type="DateTime" Name="GolCreateDate" Nullable="false" />
      <Property Type="DateTime" Name="GolTargetDate" Nullable="false" />
      <Property Type="Decimal" Name="GolCurrentAmount" Nullable="false" Precision="19" Scale="4" />
      <Property Type="Decimal" Name="GolTargetAmount" Nullable="false" Precision="19" Scale="4" />
      <Property Type="Boolean" Name="GolIsAchieved" Nullable="false" />
      <Property Type="Decimal" Name="GolMonthlyPayment" Precision="19" Scale="4" />
      <NavigationProperty Name="NavType" Relationship="IbModel.DictionaryValueFinancialGoal" FromRole="FinancialGoal" ToRole="DictionaryValue" />
    </EntityType>
    <Association Name="DictionaryValueFinancialGoal">
      <End Type="IbModel.DictionaryValue" Role="DictionaryValue" Multiplicity="1" />
      <End Type="IbModel.FinancialGoal" Role="FinancialGoal" Multiplicity="*" />
      <ReferentialConstraint>
        <Principal Role="DictionaryValue">
          <PropertyRef Name="RefId" />
        </Principal>
        <Dependent Role="FinancialGoal">
          <PropertyRef Name="RefTypeId" />
        </Dependent>
      </ReferentialConstraint>
    </Association>
    <Association Name="TagTagOverride">
      <End Type="IbModel.Tag" Role="Tag" Multiplicity="1" />
      <End Type="IbModel.TagOverride" Role="TagOverride" Multiplicity="*" />
      <ReferentialConstraint>
        <Principal Role="Tag">
          <PropertyRef Name="TtrId" />
        </Principal>
        <Dependent Role="TagOverride">
          <PropertyRef Name="TtrId" />
        </Dependent>
      </ReferentialConstraint>
    </Association>

SSDL часть:

      <EntitySet Name="vwIBGoals" EntityType="IbModel.Store.vwIBGoals" store:Type="Views" store:Schema="pub" store:Name="vwIBGoals">
        <DefiningQuery>SELECT 
  [vwIBGoals].[TtrId] AS [TtrId], 
  [vwIBGoals].[RefTypeId] AS [RefTypeId], 
  [vwIBGoals].[GolCreateDate] AS [GolCreateDate], 
  [vwIBGoals].[GolTargetDate] AS [GolTargetDate], 
  [vwIBGoals].[GolCurrentAmount] AS [GolCurrentAmount], 
  [vwIBGoals].[GolTargetAmount] AS [GolTargetAmount], 
  [vwIBGoals].[GolIsAchieved] AS [GolIsAchieved], 
  [vwIBGoals].[GolMonthlyPayment] AS [GolMonthlyPayment]
  FROM [pub].[vwIBGoals] AS [vwIBGoals]</DefiningQuery>
      </EntitySet>
      <EntitySet Name="vwIBTagTree" EntityType="IbModel.Store.vwIBTagTree" store:Type="Views" store:Schema="pub" store:Name="vwIBTagTree">
        <DefiningQuery>SELECT 
  [vwIBTagTree].[TtrId] AS [TtrId], 
  [vwIBTagTree].[TtrParentId] AS [TtrParentId], 
  [vwIBTagTree].[TtrName] AS [TtrName], 
  [vwIBTagTree].[CusId] AS [CusId], 
  [vwIBTagTree].[TtrIsExpense] AS [TtrIsExpense], 
  [vwIBTagTree].[TtrTypeFlag] AS [TtrTypeFlag], 
  [vwIBTagTree].[UsrChangeId] AS [UsrChangeId]
  FROM [pub].[vwIBTagTree] AS [vwIBTagTree]</DefiningQuery>
      </EntitySet>
      <EntitySet Name="vwIBTagTreeOverrides" EntityType="IbModel.Store.vwIBTagTreeOverrides" store:Type="Views" store:Schema="pub" store:Name="vwIBTagTreeOverrides">
        <DefiningQuery>SELECT 
  [vwIBTagTreeOverrides].[TtrId] AS [TtrId], 
  [vwIBTagTreeOverrides].[CusId] AS [CusId], 
  [vwIBTagTreeOverrides].[TtoCustomName] AS [TtoCustomName], 
  [vwIBTagTreeOverrides].[UsrChangeId] AS [UsrChangeId]
  FROM [pub].[vwIBTagTreeOverrides] AS [vwIBTagTreeOverrides]</DefiningQuery>
      </EntitySet>

    <EntityType Name="vwIBGoals">
      <Key>
        <PropertyRef Name="TtrId" />
      </Key>
      <Property Name="TtrId" Type="int" Nullable="false" />
      <Property Name="RefTypeId" Type="int" Nullable="false" />
      <Property Name="GolCreateDate" Type="datetime" Nullable="false" />
      <Property Name="GolTargetDate" Type="datetime" Nullable="false" />
      <Property Name="GolCurrentAmount" Type="numeric" Nullable="false" Precision="19" Scale="4" />
      <Property Name="GolTargetAmount" Type="numeric" Nullable="false" Precision="19" Scale="4" />
      <Property Name="GolIsAchieved" Type="bit" Nullable="false" />
      <Property Name="GolMonthlyPayment" Type="numeric" Precision="19" Scale="4" />
    </EntityType>
    <EntityType Name="vwIBTagTree">
      <Key>
        <PropertyRef Name="TtrId" />
      </Key>
      <Property Name="TtrId" Type="int" Nullable="false" StoreGeneratedPattern="Identity" />
      <Property Name="TtrParentId" Type="int" />
      <Property Name="TtrName" Type="varchar" Nullable="false" MaxLength="256" />
      <Property Name="CusId" Type="int" />
      <Property Name="TtrIsExpense" Type="bit" />
      <Property Name="TtrTypeFlag" Type="char" Nullable="false" MaxLength="1" />
      <Property Name="UsrChangeId" Type="int" />
    </EntityType>
    <EntityType Name="vwIBTagTreeOverrides">
      <Key>
        <PropertyRef Name="TtrId" />
        <PropertyRef Name="CusId" />
      </Key>
      <Property Name="TtrId" Type="int" Nullable="false" />
      <Property Name="CusId" Type="int" Nullable="false" />
      <Property Name="TtoCustomName" Type="varchar" Nullable="false" MaxLength="256" />
      <Property Name="UsrChangeId" Type="int" />
    </EntityType>

и часть отображения C-S:

        <EntityTypeMapping TypeName="IsTypeOf(IbModel.FinancialGoal)">
          <MappingFragment StoreEntitySet="vwIBGoals">
            <ScalarProperty Name="TtrId" ColumnName="TtrId" />
            <ScalarProperty Name="RefTypeId" ColumnName="RefTypeId" />
            <ScalarProperty Name="GolCreateDate" ColumnName="GolCreateDate" />
            <ScalarProperty Name="GolTargetDate" ColumnName="GolTargetDate" />
            <ScalarProperty Name="GolCurrentAmount" ColumnName="GolCurrentAmount" />
            <ScalarProperty Name="GolTargetAmount" ColumnName="GolTargetAmount" />
            <ScalarProperty Name="GolIsAchieved" ColumnName="GolIsAchieved" />
            <ScalarProperty Name="GolMonthlyPayment" ColumnName="GolMonthlyPayment" />
          </MappingFragment>
          </EntityTypeMapping>
        <EntityTypeMapping TypeName="IsTypeOf(IbModel.Tag)">
          <MappingFragment StoreEntitySet="vwIBTagTree">
            <ScalarProperty Name="TtrTypeFlag" ColumnName="TtrTypeFlag" />
            <ScalarProperty Name="TtrId" ColumnName="TtrId" />
            <ScalarProperty Name="TtrParentId" ColumnName="TtrParentId" />
            <ScalarProperty Name="TtrName" ColumnName="TtrName" />
            <ScalarProperty Name="CusId" ColumnName="CusId" />
            <ScalarProperty Name="TtrIsExpense" ColumnName="TtrIsExpense" />
            <ScalarProperty Name="UsrChangeId" ColumnName="UsrChangeId" />
          </MappingFragment>
        </EntityTypeMapping>

Любая помощь приветствуется.

1 Ответ

0 голосов
/ 14 ноября 2011

Похоже, что вы сопоставили зависимость между некоторыми сущностями в обратном порядке, и EF считает, что TtrId в Tag является внешним ключом - для внешнего ключа в EF не должно быть StoreGeneratedPattern, установленного на Identity или Computed.

...