我现在想实现每个层次结构一个表继承(table-per-hierarchy)按照MSDN的方法做了总是出错。
MSDN:http://msdn.microsoft.com/zh-cn/office/bb738443.aspxStudent是父类型
Bachelor和Doctor继承于Student环境:VS2008SP1我的部分模型如下
SSDL
<EntityType Name="Student">
<Key>
<PropertyRef Name="StudentNumber" />
</Key>
<Property Name="StudentNumber" Type="char" Nullable="false" MaxLength="12" />
<Property Name="StudentName" Type="nvarchar" Nullable="false" MaxLength="50" />
<Property Name="Sex" Type="nvarchar" Nullable="false" MaxLength="1" />
<Property Name="Birthday" Type="datetime" Nullable="false" />
<Property Name="Country" Type="nvarchar" MaxLength="20" />
<Property Name="Province" Type="nvarchar" MaxLength="20" />
<Property Name="Prefecture" Type="nvarchar" MaxLength="20" />
<Property Name="Street" Type="nvarchar" MaxLength="20" />
<Property Name="BP" Type="nvarchar" MaxLength="50" />
<Property Name="DP" Type="nvarchar" MaxLength="50" />
<Property Name="Category" Type="smallint" Nullable="false"/>
</EntityType>
CSDL
<EntityType Name="Student">
<Key>
<PropertyRef Name="StudentNumber" />
</Key>
<Property MaxLength="12" Unicode="false" FixedLength="true" Name="StudentNumber" Type="String" Nullable="false" />
<Property MaxLength="50" Unicode="true" FixedLength="false" Name="StudentName" Type="String" Nullable="false" />
<Property MaxLength="1" Unicode="true" FixedLength="false" Name="Sex" Type="String" Nullable="false" />
<Property Name="Birthday" Type="DateTime" Nullable="false" />
<Property Name="Country" Type="String" Nullable="true" />
<Property Name="Province" Type="String" Nullable="true" />
<Property Name="Prefecture" Type="String" Nullable="true" />
<Property Name="Street" Type="String" Nullable="true" />
</EntityType>
<EntityType Name="Bachelor" BaseType="StudentManagementModel.Student">
<Property Name="BP" Type="String" Nullable="true" />
</EntityType> <EntityType Name="Doctor" BaseType="StudentManagementModel.Student">
<Property Name="DP" Type="String" Nullable="true" />
</EntityType>MSL
<EntitySetMapping Name="Students">
<EntityTypeMapping TypeName="IsTypeOf(StudentManagementModel.Student)">
<MappingFragment StoreEntitySet="Student">
<ScalarProperty Name="StudentNumber" ColumnName="StudentNumber" />
<ScalarProperty Name="Street" ColumnName="Street" />
<ScalarProperty Name="Prefecture" ColumnName="Prefecture" />
<ScalarProperty Name="Province" ColumnName="Province" />
<ScalarProperty Name="Country" ColumnName="Country" />
<ScalarProperty Name="StudentName" ColumnName="StudentName" />
<ScalarProperty Name="Sex" ColumnName="Sex" />
<ScalarProperty Name="Birthday" ColumnName="Birthday" />
<Condition ColumnName="Category" Value="0" />
</MappingFragment>
</EntityTypeMapping>
<EntityTypeMapping TypeName="IsTypeOf(StudentManagementModel.Bachelor)">
<MappingFragment StoreEntitySet="Student">
<ScalarProperty Name="StudentNumber" ColumnName="StudentNumber" />
<ScalarProperty Name="Street" ColumnName="Street" />
<ScalarProperty Name="Prefecture" ColumnName="Prefecture" />
<ScalarProperty Name="Province" ColumnName="Province" />
<ScalarProperty Name="Country" ColumnName="Country" />
<ScalarProperty Name="StudentName" ColumnName="StudentName" />
<ScalarProperty Name="Sex" ColumnName="Sex" />
<ScalarProperty Name="Birthday" ColumnName="Birthday" />
<ScalarProperty Name="BP" ColumnName="BP" />
<Condition ColumnName="Category" Value="1" />
</MappingFragment>
</EntityTypeMapping>
<EntityTypeMapping TypeName="IsTypeOf(StudentManagementModel.Doctor)">
<MappingFragment StoreEntitySet="Student">
<ScalarProperty Name="StudentNumber" ColumnName="StudentNumber" />
<ScalarProperty Name="Street" ColumnName="Street" />
<ScalarProperty Name="Prefecture" ColumnName="Prefecture" />
<ScalarProperty Name="Province" ColumnName="Province" />
<ScalarProperty Name="Country" ColumnName="Country" />
<ScalarProperty Name="StudentName" ColumnName="StudentName" />
<ScalarProperty Name="Sex" ColumnName="Sex" />
<ScalarProperty Name="Birthday" ColumnName="Birthday" />
<ScalarProperty Name="DP" ColumnName="DP" />
<Condition ColumnName="Category" Value="2" />
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>错误:错误 1 错误 3034: 从第 207, 220 行开始的映射片段出现问题: 一个实体映射到同一个表中的不同行。请确保这两个映射片段不将具有重叠键的两个实体组映射到两个不同的行组。
E:\程序设计\Project\CApp\CAppTest\DAL\EDMStudentManagement.edmx 221 15 DAL如果我改成只映射Bachelor和Doctor中的特有字段报如下错误错误 1 错误 3024: 从第 220 行开始的映射片段出现问题: 必须为 EntitySet Students 的所有键属性(Students.StudentNumber)指定映射。
E:\程序设计\Project\CApp\CAppTest\DAL\EDMStudentManagement.edmx 221 15 DAL
错误 2 错误 3025: 从第 220 行开始的映射片段出现问题: 必须为表 Student 的所有键属性(Student.StudentNumber)指定映射。
E:\程序设计\Project\CApp\CAppTest\DAL\EDMStudentManagement.edmx 221 15 DAL
MSDN:http://msdn.microsoft.com/zh-cn/office/bb738443.aspxStudent是父类型
Bachelor和Doctor继承于Student环境:VS2008SP1我的部分模型如下
SSDL
<EntityType Name="Student">
<Key>
<PropertyRef Name="StudentNumber" />
</Key>
<Property Name="StudentNumber" Type="char" Nullable="false" MaxLength="12" />
<Property Name="StudentName" Type="nvarchar" Nullable="false" MaxLength="50" />
<Property Name="Sex" Type="nvarchar" Nullable="false" MaxLength="1" />
<Property Name="Birthday" Type="datetime" Nullable="false" />
<Property Name="Country" Type="nvarchar" MaxLength="20" />
<Property Name="Province" Type="nvarchar" MaxLength="20" />
<Property Name="Prefecture" Type="nvarchar" MaxLength="20" />
<Property Name="Street" Type="nvarchar" MaxLength="20" />
<Property Name="BP" Type="nvarchar" MaxLength="50" />
<Property Name="DP" Type="nvarchar" MaxLength="50" />
<Property Name="Category" Type="smallint" Nullable="false"/>
</EntityType>
CSDL
<EntityType Name="Student">
<Key>
<PropertyRef Name="StudentNumber" />
</Key>
<Property MaxLength="12" Unicode="false" FixedLength="true" Name="StudentNumber" Type="String" Nullable="false" />
<Property MaxLength="50" Unicode="true" FixedLength="false" Name="StudentName" Type="String" Nullable="false" />
<Property MaxLength="1" Unicode="true" FixedLength="false" Name="Sex" Type="String" Nullable="false" />
<Property Name="Birthday" Type="DateTime" Nullable="false" />
<Property Name="Country" Type="String" Nullable="true" />
<Property Name="Province" Type="String" Nullable="true" />
<Property Name="Prefecture" Type="String" Nullable="true" />
<Property Name="Street" Type="String" Nullable="true" />
</EntityType>
<EntityType Name="Bachelor" BaseType="StudentManagementModel.Student">
<Property Name="BP" Type="String" Nullable="true" />
</EntityType> <EntityType Name="Doctor" BaseType="StudentManagementModel.Student">
<Property Name="DP" Type="String" Nullable="true" />
</EntityType>MSL
<EntitySetMapping Name="Students">
<EntityTypeMapping TypeName="IsTypeOf(StudentManagementModel.Student)">
<MappingFragment StoreEntitySet="Student">
<ScalarProperty Name="StudentNumber" ColumnName="StudentNumber" />
<ScalarProperty Name="Street" ColumnName="Street" />
<ScalarProperty Name="Prefecture" ColumnName="Prefecture" />
<ScalarProperty Name="Province" ColumnName="Province" />
<ScalarProperty Name="Country" ColumnName="Country" />
<ScalarProperty Name="StudentName" ColumnName="StudentName" />
<ScalarProperty Name="Sex" ColumnName="Sex" />
<ScalarProperty Name="Birthday" ColumnName="Birthday" />
<Condition ColumnName="Category" Value="0" />
</MappingFragment>
</EntityTypeMapping>
<EntityTypeMapping TypeName="IsTypeOf(StudentManagementModel.Bachelor)">
<MappingFragment StoreEntitySet="Student">
<ScalarProperty Name="StudentNumber" ColumnName="StudentNumber" />
<ScalarProperty Name="Street" ColumnName="Street" />
<ScalarProperty Name="Prefecture" ColumnName="Prefecture" />
<ScalarProperty Name="Province" ColumnName="Province" />
<ScalarProperty Name="Country" ColumnName="Country" />
<ScalarProperty Name="StudentName" ColumnName="StudentName" />
<ScalarProperty Name="Sex" ColumnName="Sex" />
<ScalarProperty Name="Birthday" ColumnName="Birthday" />
<ScalarProperty Name="BP" ColumnName="BP" />
<Condition ColumnName="Category" Value="1" />
</MappingFragment>
</EntityTypeMapping>
<EntityTypeMapping TypeName="IsTypeOf(StudentManagementModel.Doctor)">
<MappingFragment StoreEntitySet="Student">
<ScalarProperty Name="StudentNumber" ColumnName="StudentNumber" />
<ScalarProperty Name="Street" ColumnName="Street" />
<ScalarProperty Name="Prefecture" ColumnName="Prefecture" />
<ScalarProperty Name="Province" ColumnName="Province" />
<ScalarProperty Name="Country" ColumnName="Country" />
<ScalarProperty Name="StudentName" ColumnName="StudentName" />
<ScalarProperty Name="Sex" ColumnName="Sex" />
<ScalarProperty Name="Birthday" ColumnName="Birthday" />
<ScalarProperty Name="DP" ColumnName="DP" />
<Condition ColumnName="Category" Value="2" />
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>错误:错误 1 错误 3034: 从第 207, 220 行开始的映射片段出现问题: 一个实体映射到同一个表中的不同行。请确保这两个映射片段不将具有重叠键的两个实体组映射到两个不同的行组。
E:\程序设计\Project\CApp\CAppTest\DAL\EDMStudentManagement.edmx 221 15 DAL如果我改成只映射Bachelor和Doctor中的特有字段报如下错误错误 1 错误 3024: 从第 220 行开始的映射片段出现问题: 必须为 EntitySet Students 的所有键属性(Students.StudentNumber)指定映射。
E:\程序设计\Project\CApp\CAppTest\DAL\EDMStudentManagement.edmx 221 15 DAL
错误 2 错误 3025: 从第 220 行开始的映射片段出现问题: 必须为表 Student 的所有键属性(Student.StudentNumber)指定映射。
E:\程序设计\Project\CApp\CAppTest\DAL\EDMStudentManagement.edmx 221 15 DAL
原文来自:雨枫技术教程网 http://www.fengfly.com
原文网址:http://www.fengfly.com/plus/view-171966-1.html