使用 XML 编辑器编辑模型:找到映射并将 IsTypeOf 添加到相应的 EntityTypeMapping 标记中。
这是一个类似于您的案例的示例:
SQL Server DDL:
创建表 [dbo].[学生] (
[Id] [int] IDENTITY(1,1) 非空,
[PartyInfo] [varchar](max) NOT NULL,
[PersonInfo] [varchar](max) 非空,
[StudInfo] [varchar](max) NOT NULL,
约束 [PK_Student] 主键集群([Id] ASC)
)
EDMX:
<?xml 版本="1.0" 编码="utf-8"?>
<edmx:Edmx 版本="1.0"
xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx">
<!-- EF 运行时内容 -->
<edmx:运行时>
<!-- SSDL 内容 -->
<edmx:StorageModels>
<Schema 命名空间="test_1Model.Store" 别名="Self"
Provider="System.Data.SqlClient" ProviderManifestToken="2005"
xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator"
xmlns="http://schemas.microsoft.com/ado/2006/04/edm/ssdl">
<EntityContainer Name="test_1ModelStoreContainer">
<EntitySet Name="Student" EntityType="test_1Model.Store.Student"
store:Type="Tables" Schema="dbo" />
</EntityContainer>
<EntityType Name="学生">
<键>
<PropertyRef Name="Id" />
</键>
<属性名称="Id" 类型="int" Nullable="false"
StoreGeneratedPattern="身份" />
<Property Name="PartyInfo" Type="varchar(max)" Nullable="false" />
<Property Name="PersonInfo" Type="varchar(max)" Nullable="false" />
<Property Name="StudInfo" Type="varchar(max)" Nullable="false" />
</EntityType>
</架构>
</edmx:StorageModels>
<!-- CSDL 内容 -->
<edmx:概念模型>
<Schema 命名空间="test_1Model" 别名="Self"
xmlns="http://schemas.microsoft.com/ado/2006/04/edm">
<EntityContainer Name="test_Entities">
<EntitySet Name="PartySet" EntityType="test_1Model.Party" />
</EntityContainer>
<EntityType Name="Party" Abstract="true">
<键>
<PropertyRef Name="Id" />
</键>
<Property Name="Id" Type="Int32" Nullable="false" />
<属性名称="PartyInfo" 类型="String" Nullable="false"
MaxLength="Max" Unicode="false" FixedLength="false" />
</EntityType>
<EntityType Name="Person" BaseType="test_1Model.Party" Abstract="true" >
<Property Name="PersonInfo" Type="String" Nullable="false" />
</EntityType>
<EntityType Name="Student" BaseType="test_1Model.Person" >
<Property Name="StudInfo" Type="String" Nullable="false" />
</EntityType>
</架构>
</edmx:概念模型>
<!-- CS映射内容-->
<edmx:映射>
<映射空间="CS"
xmlns="urn:schemas-microsoft-com:windows:storage:mapping:CS">
<EntityContainerMapping
StorageEntityContainer="test_1ModelStoreContainer"
CdmEntityContainer="test_Entities">
<EntitySetMapping Name="PartySet">
<EntityTypeMapping TypeName="IsTypeOf(test_1Model.Party)">
<MappingFragment StoreEntitySet="学生">
<ScalarProperty Name="PartyInfo" ColumnName="PartyInfo" />
<ScalarProperty Name="Id" ColumnName="Id" />
</MappingFragment>
</EntityTypeMapping>
<EntityTypeMapping TypeName="IsTypeOf(test_1Model.Person)">
<MappingFragment StoreEntitySet="学生">
<ScalarProperty Name="Id" ColumnName="Id" />
<ScalarProperty Name="PersonInfo" ColumnName="PersonInfo" />
</MappingFragment>
</EntityTypeMapping>
<EntityTypeMapping TypeName="test_1Model.Student">
<MappingFragment StoreEntitySet="学生">
<ScalarProperty Name="PartyInfo" ColumnName="PartyInfo" />
<ScalarProperty Name="PersonInfo" ColumnName="PersonInfo" />
<ScalarProperty Name="Id" ColumnName="Id" />
<ScalarProperty Name="StudInfo" ColumnName="StudInfo" />
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>
</EntityContainerMapping>
</映射>
</edmx:映射>
</edmx:运行时>
<!-- EF Designer 内容(请勿在此处手动编辑)-->
<edmx:Designer xmlns="http://schemas.microsoft.com/ado/2007/06/edmx">
<edmx:连接>
<DesignerInfoPropertySet>
<DesignerProperty Name="MetadataArtifactProcessing"
Value="EmbedInOutputAssembly" />
</DesignerInfoPropertySet>
</edmx:连接>
<edmx:选项>
<DesignerInfoPropertySet>
<DesignerProperty Name="ValidateOnBuild" Value="true" />
</DesignerInfoPropertySet>
</edmx:选项>
<!-- 图表内容(形状和连接器位置)-->
<edmx:图表>
<图表名称="SqlServer_Model" />
</edmx:图表>
</edmx:设计师>
</edmx:Edmx>