18 messaggi dal 04 giugno 2007
Ciao, ho ricostruito lo scenario di produzione in una banale applicazione riscontrando lo stesso problema; ho utilizzato il progetto EntityFrameworkProject di ASP.NET Dynamic Data 4.0 Preview 4 (UPDATED 6/26) scaricato da codeplex (L'ambiente ha Framework 3.5 SP1 + Windows Update Framework 3.5: è aggiornato all'ultimo livello)
All'interno ho semplicemente costruito il mio data model TestModel.edmx dove ho

-una entità Table1 astratta
-due entità Table1Type1 e Table1Type2 che ereditano (TPH) da Table1 (attraverso una condizione TipologiaID=1 e TipologiaID=2)
-una entità Table2 con una FK1 1-M a Table1Type1 e con una FK2 1-M a Table1Type2
(M su Table2)

Quindi una struttura piuttosto banale, ma quello che accade è questo :
alla esecuzione del codice

 
TestEntities context = new TestEntities();       
       
List<Table2> list = context.Table2.ToList();       
List<Table1Type1> list2 = context.Table1.OfType<Table1Type1>().ToList();       

viene generata l'eccezione

The relationship manager was defined with an owner of type 'DynamicDataEFProject.Table1Type1', which is not compatible with the type 'DynamicDataEFProject.Table1Type2' for the source role 'Table1Type2' in the specified relationship, 'TestModel.FK_Table1Type2_Table2'.

Se le eseguo invece in ordine inverso
       
TestEntities context = new TestEntities();       
       
List<Table1Type1> list2 = context.Table1.OfType<Table1Type1>().ToList();       
List<Table2> list = context.Table2.ToList();       

ho l'eccezione

An object of type 'DynamicDataEFProject.Table1Type1' cannot be set as the Value property for an EntityReference of type 'DynamicDataEFProject.Table1Type2'.

Va tutto bene invece se ne eseguo una sola delle due.

Vi riporto il codice del file edmx

    
<?xml version="1.0" encoding="utf-8"?>    
<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="TestModel.Store" Alias="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="TestModelStoreContainer">    
          <EntitySet Name="Table1" EntityType="TestModel.Store.Table1" store:Type="Tables" Schema="dbo" />    
          <EntitySet Name="Table2" EntityType="TestModel.Store.Table2" store:Type="Tables" Schema="dbo" />    
              
        </EntityContainer>    
        <EntityType Name="Table1">    
          <Key>    
            <PropertyRef Name="ID" />    
          </Key>    
          <Property Name="ID" Type="tinyint" Nullable="false" StoreGeneratedPattern="Identity" />    
          <Property Name="TipologiaID" Type="tinyint" Nullable="false" DefaultValue="0" />    
          <Property Name="Field1" Type="varchar" Nullable="false" MaxLength="10" />    
        </EntityType>    
        <EntityType Name="Table2">    
          <Key>    
            <PropertyRef Name="ID" />    
          </Key>    
          <Property Name="ID" Type="tinyint" Nullable="false" StoreGeneratedPattern="Identity" />    
          <Property Name="FK_Table1_ID" Type="tinyint" Nullable="false" />    
          <Property Name="Field1" Type="varchar" Nullable="false" MaxLength="50" />    
        </EntityType>    
           
      </Schema>    
    </edmx:StorageModels>    
    <!-- CSDL content -->    
    <edmx:ConceptualModels>    
      <Schema Namespace="TestModel" Alias="Self" xmlns="http://schemas.microsoft.com/ado/2006/04/edm">    
        <EntityContainer Name="TestEntities">    
          <EntitySet Name="Table1" EntityType="TestModel.Table1" />    
          <EntitySet Name="Table2" EntityType="TestModel.Table2" />    
          <AssociationSet Name="FK_Table1Type1_Table2" Association="TestModel.FK_Table1Type1_Table2">    
            <End Role="Table1Type1" EntitySet="Table1" />    
            <End Role="Table2" EntitySet="Table2" /></AssociationSet>    
          <AssociationSet Name="FK_Table1Type2_Table2" Association="TestModel.FK_Table1Type2_Table2">    
            <End Role="Table1Type2" EntitySet="Table1" />    
            <End Role="Table2" EntitySet="Table2" /></AssociationSet></EntityContainer>    
        <EntityType Name="Table1" Abstract="true">    
          <Key>    
            <PropertyRef Name="ID" />    
          </Key>    
          <Property Name="ID" Type="Byte" Nullable="false" />    
          <Property Name="Field1" Type="String" Nullable="false" MaxLength="10" Unicode="false" FixedLength="false" />    
        </EntityType>    
        <EntityType Name="Table2">    
          <Key>    
            <PropertyRef Name="ID" />    
            </Key>    
          <Property Name="ID" Type="Byte" Nullable="false" />    
          <Property Name="Field1" Type="String" Nullable="false" MaxLength="50" Unicode="false" FixedLength="false" />    
          <NavigationProperty Name="Table1Type1" Relationship="TestModel.FK_Table1Type1_Table2" FromRole="Table2" ToRole="Table1Type1" />    
          <NavigationProperty Name="Table1Type2" Relationship="TestModel.FK_Table1Type2_Table2" FromRole="Table2" ToRole="Table1Type2" /></EntityType>    
        <EntityType Name="Table1Type1" BaseType="TestModel.Table1" >    
          <NavigationProperty Name="Table2" Relationship="TestModel.FK_Table1Type1_Table2" FromRole="Table1Type1" ToRole="Table2" /></EntityType>    
        <EntityType Name="Table1Type2" BaseType="TestModel.Table1" >    
          <NavigationProperty Name="Table2" Relationship="TestModel.FK_Table1Type2_Table2" FromRole="Table1Type2" ToRole="Table2" /></EntityType>    
        <Association Name="FK_Table1Type1_Table2">    
          <End Type="TestModel.Table1Type1" Role="Table1Type1" Multiplicity="1" />    
          <End Type="TestModel.Table2" Role="Table2" Multiplicity="*" /></Association>    
        <Association Name="FK_Table1Type2_Table2">    
          <End Type="TestModel.Table1Type2" Role="Table1Type2" Multiplicity="1" />    
          <End Type="TestModel.Table2" Role="Table2" Multiplicity="*" /></Association></Schema>    
    </edmx:ConceptualModels>    
    <!-- C-S mapping content -->    
    <edmx:Mappings>    
      <Mapping Space="C-S" xmlns="urn:schemas-microsoft-com:windows:storage:mapping:CS">    
        <EntityContainerMapping StorageEntityContainer="TestModelStoreContainer" CdmEntityContainer="TestEntities">    
          <EntitySetMapping Name="Table1">    
            <EntityTypeMapping TypeName="IsTypeOf(TestModel.Table1)">    
              <MappingFragment StoreEntitySet="Table1">    
                <ScalarProperty Name="ID" ColumnName="ID" />    
                <ScalarProperty Name="Field1" ColumnName="Field1" />    
              </MappingFragment>    
            </EntityTypeMapping>    
            <EntityTypeMapping TypeName="IsTypeOf(TestModel.Table1Type1)">    
              <MappingFragment StoreEntitySet="Table1" >    
                <ScalarProperty Name="ID" ColumnName="ID" />    
                <Condition ColumnName="TipologiaID" Value="1" /></MappingFragment></EntityTypeMapping>    
            <EntityTypeMapping TypeName="IsTypeOf(TestModel.Table1Type2)">    
              <MappingFragment StoreEntitySet="Table1" >    
                <ScalarProperty Name="ID" ColumnName="ID" />    
                <Condition ColumnName="TipologiaID" Value="2" /></MappingFragment></EntityTypeMapping></EntitySetMapping>    
          <EntitySetMapping Name="Table2">    
            <EntityTypeMapping TypeName="IsTypeOf(TestModel.Table2)">    
              <MappingFragment StoreEntitySet="Table2">    
                <ScalarProperty Name="ID" ColumnName="ID" />    
                <ScalarProperty Name="Field1" ColumnName="Field1" />    
              </MappingFragment>    
            </EntityTypeMapping>    
          </EntitySetMapping>    
          <AssociationSetMapping Name="FK_Table1Type1_Table2" TypeName="TestModel.FK_Table1Type1_Table2" StoreEntitySet="Table2">    
            <EndProperty Name="Table2">    
              <ScalarProperty Name="ID" ColumnName="ID" /></EndProperty>    
            <EndProperty Name="Table1Type1">    
              <ScalarProperty Name="ID" ColumnName="FK_Table1_ID" /></EndProperty></AssociationSetMapping>    
          <AssociationSetMapping Name="FK_Table1Type2_Table2" TypeName="TestModel.FK_Table1Type2_Table2" StoreEntitySet="Table2">    
            <EndProperty Name="Table2">    
              <ScalarProperty Name="ID" ColumnName="ID" /></EndProperty>    
            <EndProperty Name="Table1Type2">    
              <ScalarProperty Name="ID" ColumnName="FK_Table1_ID" /></EndProperty></AssociationSetMapping></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="TestModel">    
        <EntityTypeShape EntityType="TestModel.Table1" Width="1.5" PointX="3" PointY="1.125" Height="1.4033821614583331" IsExpanded="true" />    
        <EntityTypeShape EntityType="TestModel.Table2" Width="3.125" PointX="2.25" PointY="4.75" Height="1.7879850260416657" IsExpanded="true" />    
        <EntityTypeShape EntityType="TestModel.Table1Type1" Width="1.5" PointX="2.25" PointY="3" Height="1.2110807291666665" />    
        <InheritanceConnector EntityType="TestModel.Table1Type1" ManuallyRouted="false">    
          <ConnectorPoint PointX="3.375" PointY="2.5283821614583331" />    
          <ConnectorPoint PointX="3.375" PointY="3" />    
          </InheritanceConnector>    
        <EntityTypeShape EntityType="TestModel.Table1Type2" Width="1.5" PointX="3.875" PointY="3" Height="1.2110807291666665" />    
        <InheritanceConnector EntityType="TestModel.Table1Type2" ManuallyRouted="false">    
          <ConnectorPoint PointX="4.1875" PointY="2.5283821614583331" />    
          <ConnectorPoint PointX="4.1875" PointY="3" />    
          </InheritanceConnector>    
        <AssociationConnector Association="TestModel.FK_Table1Type1_Table2">    
          <ConnectorPoint PointX="3" PointY="4.2110807291666665" />    
          <ConnectorPoint PointX="3" PointY="4.75" /></AssociationConnector>    
        <AssociationConnector Association="TestModel.FK_Table1Type2_Table2">    
          <ConnectorPoint PointX="4.625" PointY="4.2110807291666665" />    
          <ConnectorPoint PointX="4.625" PointY="4.75" /></AssociationConnector></Diagram></edmx:Diagrams>    
  </edmx:Designer>    
</edmx:Edmx>    


Cosa mi sfugge ? Dove sbaglio ?

Grazie anticipatamente.
http://
Modificato da StefanoFar il 23 luglio 2009 14.21 -
Modificato da StefanoFar il 23 luglio 2009 14.23 -

Stefano

Torna al forum | Feed RSS

ASPItalia.com non è responsabile per il contenuto dei messaggi presenti su questo servizio, non avendo nessun controllo sui messaggi postati nei propri forum, che rappresentano l'espressione del pensiero degli autori.