2009-06-18 66 views
2

我已經在EDM中編寫了一個項目。有誰知道如何從TPH繼承樹中的實體獲取鑑別器列的值嗎?我無法將該屬性添加到實體。有沒有其他的方式來獲得價值?如何從實體框架實體中獲取歧視器列的值

謝謝
羅伊

+0

你爲什麼需要它? – 2009-06-19 12:37:55

回答

2

還有就是要解決這個問題對於suports更新視圖的數據庫管理系統的簡單方法。 您可以簡單地創建一個視圖或具有附加鑑別器列的定義查詢。 原始列應映射到類屬性。如果DBMS不支持可更新視圖,則可以使用定義查詢,然後映射插入/更新/刪除操作的存儲過程。

下面是Oracle數據庫的例子:

 
SQL: 
CREATE TABLE TEST.TPH_TABLE (
    ID NUMBER(9), 
    COLUMN_A VARCHAR2(20), 
    COLUMN_B VARCHAR2(20), 
    BASE_COLUMN VARCHAR2(20), 
    CONSTRAINT PK_TPH_TABLE PRIMARY KEY (ID) 
); 

EDMX: 
<edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx"> 
    <!-- EF Runtime content --> 
    <edmx:Runtime> 
    <!-- SSDL content --> 
    <edmx:StorageModels> 
     <Schema Namespace="Model1.Store" Alias="Self" Provider="Devart.Data.Oracle" ProviderManifestToken="ORA" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2006/04/edm/ssdl"> 
     <EntityContainer Name="Model1StoreContainer"> 
      <EntitySet Name="TPH_TABLE" EntityType="Model1.Store.TPH_TABLE" > 
      <DefiningQuery> 
       SELECT ID, BASE_COLUMN, COLUMN_A, COLUMN_B, 
        CASE WHEN COLUMN_A IS NOT NULL THEN '1' ELSE NULL END AS "IS_TABLE_A" 
       FROM TPH_TABLE 
      </DefiningQuery> 
      </EntitySet> 
     </EntityContainer> 
     <EntityType Name="TPH_TABLE"> 
      <Key> 
      <PropertyRef Name="ID" /> 
      </Key> 
      <Property Name="ID" Type="int" Nullable="false" /> 
      <Property Name="BASE_COLUMN" Type="VARCHAR2" MaxLength="20" /> 
      <Property Name="COLUMN_A" Type="VARCHAR2" MaxLength="20" /> 
      <Property Name="COLUMN_B" Type="VARCHAR2" MaxLength="20" /> 
      <Property Name="IS_TABLE_A" Type="VARCHAR2" MaxLength="1" /> 
     </EntityType> 
     </Schema> 
    </edmx:StorageModels> 
    <!-- CSDL content --> 
    <edmx:ConceptualModels> 
     <Schema Namespace="Model1" Alias="Self" xmlns="http://schemas.microsoft.com/ado/2006/04/edm"> 
     <EntityContainer Name="Entities"> 
      <EntitySet Name="TPH_TABLE" EntityType="Model1.TPH_TABLE" /> 
     </EntityContainer> 
     <EntityType Name="TPH_TABLE" Abstract="true"> 
      <Key> 
      <PropertyRef Name="ID" /> 
      </Key> 
      <Property Name="ID" Type="Int32" Nullable="false" /> 
      <Property Name="BASE_COLUMN" Type="String" MaxLength="20" Unicode="true" FixedLength="false" /> 
     </EntityType> 
     <EntityType Name="TABLE_A" BaseType="Model1.TPH_TABLE" > 
      <Property Name="COLUMN_A" Type="String" Nullable="true" /> 
     </EntityType> 
     <EntityType Name="TABLE_B" BaseType="Model1.TPH_TABLE" > 
      <Property Name="COLUMN_B" Type="String" Nullable="true" /> 
     </EntityType> 
     </Schema> 
    </edmx:ConceptualModels> 
    <!-- C-S mapping content --> 
    <edmx:Mappings> 
     <Mapping Space="C-S" xmlns="urn:schemas-microsoft-com:windows:storage:mapping:CS"> 
     <EntityContainerMapping StorageEntityContainer="Model1StoreContainer" CdmEntityContainer="Entities"> 
      <EntitySetMapping Name="TPH_TABLE"> 
      <EntityTypeMapping TypeName="Model1.TABLE_A"> 
       <MappingFragment StoreEntitySet="TPH_TABLE"> 
       <ScalarProperty Name="ID" ColumnName="ID" /> 
       <ScalarProperty Name="BASE_COLUMN" ColumnName="BASE_COLUMN" /> 
       <ScalarProperty Name="COLUMN_A" ColumnName="COLUMN_A" /> 
       <Condition ColumnName="IS_TABLE_A" Value="1" /> 
       </MappingFragment> 
      </EntityTypeMapping> 
      <EntityTypeMapping TypeName="Model1.TABLE_B"> 
       <MappingFragment StoreEntitySet="TPH_TABLE"> 
       <ScalarProperty Name="ID" ColumnName="ID" /> 
       <ScalarProperty Name="BASE_COLUMN" ColumnName="BASE_COLUMN" /> 
       <ScalarProperty Name="COLUMN_B" ColumnName="COLUMN_B" /> 
       <Condition ColumnName="IS_TABLE_A" IsNull="true" /> 
       </MappingFragment> 
      </EntityTypeMapping> 
      </EntitySetMapping> 
     </EntityContainerMapping> 
     </Mapping> 
    </edmx:Mappings> 
    </edmx:Runtime> 
    <!-- EF Designer content (DO NOT EDIT MANUALLY BELOW HERE) --> 
    <edmx:Designer xmlns="http://schemas.microsoft.com/ado/2007/06/edmx"> 
    <edmx:Connection> 
     <DesignerInfoPropertySet> 
     <DesignerProperty Name="MetadataArtifactProcessing" Value="EmbedInOutputAssembly" /> 
     </DesignerInfoPropertySet> 
    </edmx:Connection> 
    <edmx:Options> 
     <DesignerInfoPropertySet> 
     <DesignerProperty Name="ValidateOnBuild" Value="true" /> 
     </DesignerInfoPropertySet> 
    </edmx:Options> 
    <!-- Diagram content (shape and connector positions) --> 
    <edmx:Diagrams> 
     <Diagram Name="Model4"> 
     <EntityTypeShape EntityType="Model1.TPH_TABLE" Width="1.5" PointX="3" PointY="0.5" Height="1.2636116536458335" IsExpanded="true" /> 
     <EntityTypeShape EntityType="Model1.TABLE_A" Width="1.5" PointX="1.75" PointY="2.75" Height="1.099264322916667" /> 
     <EntityTypeShape EntityType="Model1.TABLE_B" Width="1.5" PointX="4.25" PointY="2.75" Height="1.099264322916667" /> 
     <InheritanceConnector EntityType="Model1.TABLE_B" ManuallyRouted="false"> 
      <ConnectorPoint PointX="4.375" PointY="1.7636116536458335" /> 
      <ConnectorPoint PointX="4.375" PointY="2.75" /> 
      </InheritanceConnector> 
     <InheritanceConnector EntityType="Model1.TABLE_A" ManuallyRouted="false"> 
      <ConnectorPoint PointX="3.125" PointY="1.7636116536458335" /> 
      <ConnectorPoint PointX="3.125" PointY="2.75" /> 
      </InheritanceConnector></Diagram></edmx:Diagrams> 
    </edmx:Designer> 
</edmx:Edmx>