美好的一天!
我们的EF数据模型中有TPT继承,基于数据库中的视图集和存储过程。有基本实体标记,它不是抽象的,具有主键TtrId和继承的实体 FinancialGoal 。 标记实体基于视图vwTagTree, FinancialGoal 基于视图vwGoals。两个视图都具有字段TtrId一对一实现关系。每个实体都与其他模型实体相关联。实体标记的字段TtrId具有属性StoreGeneratedPattern = Identity,但它不作为依赖字段参与任何关联。
但是,我们收到错误“ ReferentialConstraint中的依赖属性映射到存储生成的列。列:'TtrId'。”,同时尝试添加 FinancialGoal 对象。选择正常,更新正常,插入标记对象即可,但插入 FinancialGoal 对象会引发上述错误。
以下是EF模型图的一部分:
遗憾的是,由于信誉不佳,我无法发布截图,因此这是EDDL定义的CSDL部分:
<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>
任何帮助表示感谢。
答案 0 :(得分:0)
听起来你已经按照相反的顺序映射了某些实体之间的依赖关系,并且EF认为TtrId
中的Tag
是外键 - EF中的外键不能将StoreGeneratedPattern
设置为Identity
或Computed
。