【发布时间】:2015-08-12 09:45:13
【问题描述】:
我从 Entity Framework v4 收到以下错误:
主体角色单元引用的属性必须与关系 dbSamplingModel.UnitSource 的关系约束中主体角色所引用的 EntityType dbSamplingModel.Unit 的键完全相同。确保在 Principal Role 中指定了所有关键属性。
这是我的 edmx 的相关部分。据我所知,我的单位是由 CitiCode 键入的,这就是我在关系中使用的键。
<EntityType Name="Unit">
<Key>
<PropertyRef Name="CitiCode" />
</Key>
<Property Name="CitiCode" Type="String" Nullable="false" MaxLength="15" FixedLength="false" Unicode="false" />
<Property Name="SedolCode" Type="String" Nullable="false" MaxLength="15" FixedLength="false" Unicode="false" />
<Property Name="ISINCode" Type="String" Nullable="false" MaxLength="15" FixedLength="false" Unicode="false" />
<Property Name="MexCode" Type="String" Nullable="false" MaxLength="15" FixedLength="false" Unicode="false" />
<NavigationProperty Name="Sources" Relationship="dbSamplingModel.UnitSource" FromRole="Unit" ToRole="Source" />
</EntityType>
<Association Name="UnitSource">
<End Type="dbSamplingModel.Unit" Role="Unit" Multiplicity="1" />
<End Type="dbSamplingModel.Source" Role="Source" Multiplicity="*" />
<ReferentialConstraint>
<Principal Role="Unit">
<PropertyRef Name="CitiCode" />
</Principal>
<Dependent Role="Source">
<PropertyRef Name="CitiCode" />
</Dependent>
</ReferentialConstraint>
</Association>
【问题讨论】:
标签: entity-framework entity-framework-4