2010-01-11 6 views
1

J'ai essayé ceci: http://channel9.msdn.com/posts/RobBagby/deCast-Entity-Framework-Modeling-Implementing-Entity-Splitting/Default.aspx?wa=wsignin1.0Comment faire une jointure simple avec le concepteur de modèle de données de framework d'entité?

... avec la base de données Northwind de Codeplex, en utilisant les tables des employés et de contact. Je voulais créer une entité EmployeeContact qui extrait essentiellement les colonnes FirstName et LastName du Contact. J'ai donc copié et collé ces propriétés et la propriété ContactID de l'entité Contact à l'entité Employee. "Erreur 3024: Problème dans le mappage des fragments à partir de la ligne 389: doit spécifier le mappage pour toutes les propriétés de clé (Employees.EmployeeID) des employés EntitySet " Et d'ailleurs, comment obtenir VS pour me montrer le balisage du fichier de mappage au lieu de me montrer le concepteur? Au moins peut-être alors je pourrais commencer à voir la source de l'erreur, car il fait référence à un numéro de ligne spécifique.

Cette propriété est mappée, en ce sens que la vue Détails de mappage affiche une affectation de la colonne de table à la propriété d'entité du même nom, qui a déjà été générée de cette manière pour moi. Il m'a fallu un bon bout de chemin pour arriver à ce point, et il est frustrant que la création de ce qui serait normalement une simple jointure soit si problématique. Je déteste imaginer les problèmes que l'on court pour faire quoi que ce soit, même un peu plus complexe. Je suis sûr que quelqu'un me suggérera d'utiliser LINQ, mais je pensais que le but d'Entity Framework était de faire en sorte que vous pensiez davantage à la signification des données et moins à la structure relationnelle. En d'autres termes, ne pas avoir à faire de nombreuses jointures chaque fois que vous vouliez un simple ensemble de données.

Merci d'avance.

Me voilà edmx fichier, j'ai dépouillé la section mappings pour essayer de le compiler:

<?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="AdventureWorksModel.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2008" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2006/04/edm/ssdl"> 
     <EntityContainer Name="AdventureWorksModelStoreContainer"> 
      <EntitySet Name="Employee" EntityType="AdventureWorksModel.Store.Employee" store:Type="Tables" Schema="HumanResources" /> 
      <EntitySet Name="Contact" EntityType="AdventureWorksModel.Store.Contact" Schema="Person" store:Type="Tables" /> 
      <AssociationSet Name="FK_Employee_Contact_ContactID" Association="AdventureWorksModel.Store.FK_Employee_Contact_ContactID"> 
      <End EntitySet="Contact" Role="Contact" /> 
      <End EntitySet="Employee" Role="Employee" /> 
      </AssociationSet> 
      <AssociationSet Name="FK_Employee_Employee_ManagerID" Association="AdventureWorksModel.Store.FK_Employee_Employee_ManagerID"> 
      <End Role="Employee" EntitySet="Employee" /> 
      <End Role="Employee1" EntitySet="Employee" /> 
      </AssociationSet> 
     </EntityContainer> 
     <EntityType Name="Employee"> 
      <Key> 
      <PropertyRef Name="EmployeeID" /> 
      </Key> 
      <Property Name="EmployeeID" Type="int" Nullable="false" StoreGeneratedPattern="Identity" /> 
      <Property Name="NationalIDNumber" Type="nvarchar" Nullable="false" MaxLength="15" /> 
      <Property Name="ContactID" Type="int" Nullable="false" /> 
      <Property Name="LoginID" Type="nvarchar" Nullable="false" MaxLength="256" /> 
      <Property Name="ManagerID" Type="int" /> 
      <Property Name="Title" Type="nvarchar" Nullable="false" MaxLength="50" /> 
      <Property Name="BirthDate" Type="datetime" Nullable="false" /> 
      <Property Name="MaritalStatus" Type="nchar" Nullable="false" MaxLength="1" /> 
      <Property Name="Gender" Type="nchar" Nullable="false" MaxLength="1" /> 
      <Property Name="HireDate" Type="datetime" Nullable="false" /> 
      <Property Name="SalariedFlag" Type="bit" Nullable="false" /> 
      <Property Name="VacationHours" Type="smallint" Nullable="false" /> 
      <Property Name="SickLeaveHours" Type="smallint" Nullable="false" /> 
      <Property Name="CurrentFlag" Type="bit" Nullable="false" /> 
      <Property Name="rowguid" Type="uniqueidentifier" Nullable="false" /> 
      <Property Name="ModifiedDate" Type="datetime" Nullable="false" /> 
     </EntityType> 
     <EntityType Name="Contact"> 
      <Key> 
      <PropertyRef Name="ContactID" /> 
      </Key> 
      <Property StoreGeneratedPattern="Identity" Name="ContactID" Nullable="false" Type="int" /> 
      <Property Name="NameStyle" Nullable="false" Type="bit" /> 
      <Property Name="Title" MaxLength="8" Type="nvarchar" /> 
      <Property Name="FirstName" Nullable="false" MaxLength="50" Type="nvarchar" /> 
      <Property Name="MiddleName" MaxLength="50" Type="nvarchar" /> 
      <Property Name="LastName" Nullable="false" MaxLength="50" Type="nvarchar" /> 
      <Property Name="Suffix" MaxLength="10" Type="nvarchar" /> 
      <Property Name="EmailAddress" MaxLength="50" Type="nvarchar" /> 
      <Property Name="EmailPromotion" Nullable="false" Type="int" /> 
      <Property Name="Phone" MaxLength="25" Type="nvarchar" /> 
      <Property Name="PasswordHash" Nullable="false" MaxLength="128" Type="varchar" /> 
      <Property Name="PasswordSalt" Nullable="false" MaxLength="10" Type="varchar" /> 
      <Property Name="AdditionalContactInfo" Type="xml" /> 
      <Property Name="rowguid" Nullable="false" Type="uniqueidentifier" /> 
      <Property Name="ModifiedDate" Nullable="false" Type="datetime" /> 
     </EntityType> 
     <Association Name="FK_Employee_Contact_ContactID"> 
      <End Type="AdventureWorksModel.Store.Contact" Multiplicity="1" Role="Contact" /> 
      <End Type="AdventureWorksModel.Store.Employee" Multiplicity="*" Role="Employee" /> 
      <ReferentialConstraint> 
      <Principal Role="Contact"> 
       <PropertyRef Name="ContactID" /> 
      </Principal> 
      <Dependent Role="Employee"> 
       <PropertyRef Name="ContactID" /> 
      </Dependent> 
      </ReferentialConstraint> 
     </Association> 
     <Association Name="FK_Employee_Employee_ManagerID"> 
      <End Role="Employee" Type="AdventureWorksModel.Store.Employee" Multiplicity="0..1" /> 
      <End Role="Employee1" Type="AdventureWorksModel.Store.Employee" Multiplicity="*" /> 
      <ReferentialConstraint> 
      <Principal Role="Employee"> 
       <PropertyRef Name="EmployeeID" /> 
      </Principal> 
      <Dependent Role="Employee1"> 
       <PropertyRef Name="ManagerID" /> 
      </Dependent> 
      </ReferentialConstraint> 
     </Association> 
     </Schema> 
    </edmx:StorageModels> 
    <!-- CSDL content --> 
    <edmx:ConceptualModels> 
     <Schema Namespace="AdventureWorksModel" Alias="Self" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns="http://schemas.microsoft.com/ado/2006/04/edm"> 
     <EntityContainer Name="AdventureWorksEntities"> 
      <EntitySet Name="EmployeeContacts" EntityType="AdventureWorksModel.EmployeeContact" /> 
      </EntityContainer> 
     <EntityType Name="EmployeeContact"> 
      <Key> 
      <PropertyRef Name="ContactID" />    
      </Key> 
      <Property Name="EmployeeID" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" /> 
      <Property Name="NationalIDNumber" Type="String" Nullable="false" MaxLength="15" Unicode="true" FixedLength="false" /> 
      <Property Name="LoginID" Type="String" Nullable="false" MaxLength="256" Unicode="true" FixedLength="false" /> 
      <Property Name="Title" Type="String" Nullable="false" MaxLength="50" Unicode="true" FixedLength="false" /> 
      <Property Name="BirthDate" Type="DateTime" Nullable="false" /> 
      <Property Name="MaritalStatus" Type="String" Nullable="false" MaxLength="1" Unicode="true" FixedLength="true" /> 
      <Property Name="Gender" Type="String" Nullable="false" MaxLength="1" Unicode="true" FixedLength="true" /> 
      <Property Name="HireDate" Type="DateTime" Nullable="false" /> 
      <Property Name="SalariedFlag" Type="Boolean" Nullable="false" /> 
      <Property Name="VacationHours" Type="Int16" Nullable="false" /> 
      <Property Name="SickLeaveHours" Type="Int16" Nullable="false" /> 
      <Property Name="CurrentFlag" Type="Boolean" Nullable="false" /> 
      <Property Name="rowguid" Type="Guid" Nullable="false" /> 
      <Property Name="ModifiedDate" Type="DateTime" Nullable="false" /> 
      <Property Type="String" Name="FirstName" Nullable="false" MaxLength="50" FixedLength="false" Unicode="true" /> 
      <Property Type="String" Name="MiddleName" MaxLength="50" FixedLength="false" Unicode="true" /> 
      <Property Type="String" Name="LastName" Nullable="false" MaxLength="50" FixedLength="false" Unicode="true" /> 
      <Property Type="Int32" Name="ContactID" Nullable="false" annotation:StoreGeneratedPattern="Identity" /> 
     </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="AdventureWorksModelStoreContainer" CdmEntityContainer="AdventureWorksEntities"> 
      <EntitySetMapping Name="EmployeeContacts">    
      <EntityTypeMapping TypeName="IsTypeOf(AdventureWorksModel.EmployeeContact)">    
       <MappingFragment StoreEntitySet="Employee"> 
       <Condition ColumnName="ContactID" IsNull="false"/>     
       <ScalarProperty Name="ContactID" ColumnName="ContactID"/> 
       </MappingFragment> 
       <MappingFragment StoreEntitySet="Contact"> 
       <ScalarProperty Name="ContactID" ColumnName="ContactID"/> 
       </MappingFragment> 
      </EntityTypeMapping> 
      </EntitySetMapping> 
      </EntityContainerMapping> 
     </Mapping> 
    </edmx:Mappings> 
    </edmx:Runtime> 
    <!-- EF Designer content (DO NOT EDIT MANUALLY BELOW HERE) --> 
    <Designer xmlns="http://schemas.microsoft.com/ado/2007/06/edmx"> 
    <Connection> 
     <DesignerInfoPropertySet> 
     <DesignerProperty Name="MetadataArtifactProcessing" Value="EmbedInOutputAssembly" /> 
     </DesignerInfoPropertySet> 
    </Connection> 
    <Options> 
     <DesignerInfoPropertySet> 
     <DesignerProperty Name="ValidateOnBuild" Value="true" /> 
     <DesignerProperty Name="EnablePluralization" Value="True" /> 
     <DesignerProperty Name="IncludeForeignKeysInModel" Value="False" /> 
     </DesignerInfoPropertySet> 
    </Options> 
    <!-- Diagram content (shape and connector positions) --> 
    <Diagrams> 
     <Diagram Name="Model1" ZoomLevel="70"> 
     <EntityTypeShape EntityType="AdventureWorksModel.EmployeeContact" Width="1.5" PointX="3.25" PointY="0.5" Height="4.480205078125" IsExpanded="true" /> 
     </Diagram></Diagrams> 
    </Designer> 
</edmx:Edmx> 
+1

Vous pouvez obtenir Visual Studio pour afficher le balisage XML du fichier edmx en cliquant avec le bouton droit de la souris sur le fichier, sélectionnez 'Ouvrir avec' puis en sélectionnant 'Éditeur XML' dans la boîte de dialogue Ouvrir avec. – DaveB

Répondre

0

Je genre de abandonnèrent à ce sujet, se rendre compte qu'il ne semble pas être prévu être utilisé de cette façon. Au lieu de cela, je vais juste me contenter de parcourir les propriétés de navigation, ce qui est comme faire une jointure, sauf dans un mode OO plus facile.

Questions connexes