Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 如何与实体框架数据模型设计器进行简单连接?_.net_Entity Framework - Fatal编程技术网

.net 如何与实体框架数据模型设计器进行简单连接?

.net 如何与实体框架数据模型设计器进行简单连接?,.net,entity-framework,.net,Entity Framework,我试过这个: …使用Codeplex的Northwind样本数据库,使用员工和联系人表。我想创建一个EmployeeContact实体,基本上从联系人中提取FirstName和LastName列。因此,我将这些属性和ContactID属性从Contact实体复制并粘贴到Employee实体。我映射了所有这些,但现在在映射EmployeeID属性时出现错误: 错误3024:映射从第389行开始的片段时出现问题:必须为EntitySet Employees的所有关键属性EmployeeID指定映射

我试过这个:

…使用Codeplex的Northwind样本数据库,使用员工和联系人表。我想创建一个EmployeeContact实体,基本上从联系人中提取FirstName和LastName列。因此,我将这些属性和ContactID属性从Contact实体复制并粘贴到Employee实体。我映射了所有这些,但现在在映射EmployeeID属性时出现错误:

错误3024:映射从第389行开始的片段时出现问题:必须为EntitySet Employees的所有关键属性EmployeeID指定映射

对于这个问题,我如何让VS向我显示映射文件的标记,而不是向我显示设计器?至少我可以开始看到错误的来源,因为它引用了一个特定的行号

此属性已映射,因为Mapping Details视图显示了从表列到同名实体属性的赋值,该赋值已经以这种方式为我生成。我花了很长时间才达到这一点,令人沮丧的是,创建一个通常是简单连接的东西是如此困难。我讨厌想象一个人在做任何稍微复杂一点的事情时遇到的问题

我相信有人会建议我使用LINQ,但我认为实体框架的全部目的是让它更具代表性,因此您更多地考虑数据的含义,而较少考虑关系结构?换句话说,不必每次需要一组简单的数据时都进行大量的连接

提前谢谢

这是我的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="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>

我有点放弃了,因为我意识到它似乎不打算这样使用。相反,我只需要遍历导航属性就可以了,这就像进行连接一样,只是采用了一种更简单的OO方式。

您可以让Visual Studio显示edmx文件的XML标记,方法是右键单击该文件,选择“打开方式”,然后从“打开方式”对话框中选择“XML编辑器”。