Oracle
 sql >> Base de données >  >> RDS >> Oracle

L'entité Oracle dans le cadre d'entité VS ne met pas à jour la clé primaire dans le code

Ouvrez le fichier .edmx avec l'éditeur XML et recherchez la section qui commence par la ligne suivante :

<!-- SSDL content -->

Ci-dessous devrait être une balise EntityType et dans celle-ci se trouve une définition de la table de base de données. Assurez-vous que la propriété de votre colonne ID a StoreGeneratedPattern="Identity" dedans.

Sous cette section SSDL se trouve une section CSDL qui semble similaire, mais qui définit l'objet C# qui représente cette entité. Le concepteur visuel ne semble remplir que le StoreGeneratedPatterdans cette section, mais pas la section SSDL.

MODIFIER AVEC ÉCHANTILLON

Voici un exemple de fichier EDMX pour une entité Employee, avec rien d'autre qu'une propriété ID, FirstName et LastName. L'ID est le champ que vous souhaitez générer automatiquement par la base de données. Notez qu'il existe deux endroits différents où StoreGeneratedPattern est nécessaire.

<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="2.0" xmlns:edmx="http://schemas.microsoft.com/ado/2008/10/edmx">
  <!-- EF Runtime content -->
  <edmx:Runtime>
    <!-- SSDL content -->
    <edmx:StorageModels>
      <Schema Namespace="Store" Alias="Self" Provider="Oracle.DataAccess.Client" ProviderManifestToken="10g"
              xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator"
              xmlns="http://schemas.microsoft.com/ado/2009/02/edm/ssdl">
        <EntityContainer Name="StoreContainer">
          <EntitySet Name="EMPLOYEE" EntityType="Store.EMPLOYEE" store:Type="Tables" Schema="TESTSPACE" />
        </EntityContainer>
        <EntityType Name="EMPLOYEE">
          <Key>
            <PropertyRef Name="ID" />
          </Key>
          <!-- The below property requires StoreGeneratedPattern="Identity" -->
          <Property Name="ID" Type="number" StoreGeneratedPattern="Identity" Nullable="false" Precision="10" />
          <Property Name="FIRST_NAME" Type="varchar2" MaxLength="255" />
          <Property Name="LAST_NAME" Type="varchar2" MaxLength="255" />
        </EntityType>
      </Schema>
    </edmx:StorageModels>
    <!-- CSDL content -->
    <edmx:ConceptualModels>
      <Schema xmlns="http://schemas.microsoft.com/ado/2008/09/edm"
              xmlns:cg="http://schemas.microsoft.com/ado/2006/04/codegeneration"
              xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" Namespace="Model" Alias="Self"
              xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation">
        <EntityContainer Name="ModelContainer" annotation:LazyLoadingEnabled="true">
          <EntitySet Name="Employees1" EntityType="Model.Employee" />
        </EntityContainer>
        <EntityType Name="Employee">
          <Key>
            <PropertyRef Name="ID" />
          </Key>
          <!-- The below property requires StoreGeneratedPattern="Identity" -->
          <Property Type="Int32" Name="ID" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
          <Property Type="String" Name="FirstName" MaxLength="255" FixedLength="false" Unicode="false" />
          <Property Type="String" Name="LastName" MaxLength="255" FixedLength="false" Unicode="false" />
        </EntityType>
      </Schema>
    </edmx:ConceptualModels>
    <!-- C-S mapping content -->
    <edmx:Mappings>
      <Mapping Space="C-S" xmlns="http://schemas.microsoft.com/ado/2008/09/mapping/cs">
        <EntityContainerMapping StorageEntityContainer="StoreContainer" CdmEntityContainer="ModelContainer">
          <EntitySetMapping Name="Employees1">
            <EntityTypeMapping TypeName="Model.Employee">
              <MappingFragment StoreEntitySet="EMPLOYEE">
                <ScalarProperty Name="LastName" ColumnName="LAST_NAME" />
                <ScalarProperty Name="FirstName" ColumnName="FIRST_NAME" />
                <ScalarProperty Name="ID" ColumnName="ID" />
              </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/2008/10/edmx">
    <edmx:Connection>
      <DesignerInfoPropertySet>
        <DesignerProperty Name="MetadataArtifactProcessing" Value="EmbedInOutputAssembly" />
      </DesignerInfoPropertySet>
    </edmx:Connection>
    <edmx:Options>
      <DesignerInfoPropertySet>
        <DesignerProperty Name="ValidateOnBuild" Value="true" />
        <DesignerProperty Name="EnablePluralization" Value="True" />
        <DesignerProperty Name="IncludeForeignKeysInModel" Value="True" />
      </DesignerInfoPropertySet>
    </edmx:Options>
    <!-- Diagram content (shape and connector positions) -->
    <edmx:Diagrams>
      <Diagram Name="Model">
        <EntityTypeShape EntityType="Model.Employee" Width="1.5" PointX="0.75" PointY="0.75"
                         Height="1.4279589843749996" />
      </Diagram>
    </edmx:Diagrams>
  </edmx:Designer>
</edmx:Edmx>