おはよう!EF 4.1 TPT継承により、「ReferentialConstraintの依存プロパティがストア生成カラムにマップされます」
データベースのビューとストアドプロシージャのセットに基づいて、私たちのEFデータモデルにTPT継承があります。基底エンティティタグがあります。抽象的ではなく、主キーTtrIdを持ち、継承されたエンティティFinancialGoalです。 タグビューに基づくエンティティvwTagTree、FinancialGoalビューvwGoalsに基づく。どちらのビューも、フィールドTtrIdに1対1の関係を実装しています。各エンティティは他のモデルエンティティと関連しています。エンティティのフィールドTtrIdタグは、属性StoreGeneratedPattern = Identityを持ちますが、従属フィールドとしての関連付けには参加しません。 FinancialGoalオブジェクトを追加しようとしているとき:
しかし、我々は、エラーを取得している「『TtrId』。。ReferentialConstraintで依存プロパティは、ストア生成された列の列にマッピングされています」。選択はOK、更新はOKです。タグオブジェクトはOKですが、FinancialGoalオブジェクトを挿入すると上記のエラーが発生します。ここで
はEFモデル図の一部である:
<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パーツ:
は、残念ながら私は、低い評判にスクリーンショットを投稿することはできませんので、ここでEDMX定義のCSDLの一部であり、
<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>
とCSマッピング部:
<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>
助けていただければ幸いです。 EFの外部キーはIdentity
またはComputed
にStoreGeneratedPattern
セットを持っていなければなりません - あなたが逆の順序でいくつかのエンティティ間の依存関係をマッピングしているとEFはTag
でTtrId
が外部キーであると考えているよう
この状況で最も興味深いのは、EFモデルからDictionaryValueFinancialGoalの関連付けを削除するとエラーが表示されなくなります。これはEFのバグのようです:( – Grayver