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
Entity framework 如何在不接触数据库的情况下创建这两个实体之间的关联?_Entity Framework_Entity Framework 4_Associations_Edmx - Fatal编程技术网

Entity framework 如何在不接触数据库的情况下创建这两个实体之间的关联?

Entity framework 如何在不接触数据库的情况下创建这两个实体之间的关联?,entity-framework,entity-framework-4,associations,edmx,Entity Framework,Entity Framework 4,Associations,Edmx,我需要在这两个实体(1-*)之间创建一个“虚拟”关联,以便使用linq遍历它们,但问题是我无法接触数据库。我曾多次尝试手动编辑edmx,但均未成功,导致各种映射错误 EDMX: <?xml version="1.0" encoding="utf-8"?> <edmx:Edmx Version="2.0" xmlns:edmx="http://schemas.microsoft.com/ado/2008/10/edmx"> <!-- EF Runtime c

我需要在这两个实体(1-*)之间创建一个“虚拟”
关联
,以便使用
linq
遍历它们,但问题是我无法接触数据库。我曾多次尝试手动编辑
edmx
,但均未成功,导致各种映射错误

EDMX:

<?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="DataAccess.SD.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/2009/02/edm/ssdl">
                <EntityContainer Name="SDModelsStoreContainer">
                    <EntitySet Name="CUSTOMER" EntityType="DataAccess.SD.Store.CUSTOMER" store:Type="Tables" Schema="PINNACLE" />
                    <EntitySet Name="EQUIPMENT" EntityType="DataAccess.SD.Store.EQUIPMENT" store:Type="Tables" Schema="PINNACLE" />
                </EntityContainer>
                <EntityType Name="CUSTOMER">
                    <Key>
                        <PropertyRef Name="CUSTOMEROID" />
                    </Key>
                    <Property Name="CUSTOMEROID" Type="int64" Nullable="false" />
                    <Property Name="CUSTOMER_NAME" Type="VARCHAR2" MaxLength="40" />
                    <Property Name="CUSTOMER_ACCOUNT" Type="VARCHAR2" MaxLength="20" />
                </EntityType>
                <EntityType Name="EQUIPMENT">
                    <Key>
                        <PropertyRef Name="EQUIPMENTOID" />
                    </Key>
                    <Property Name="EQUIPMENTOID" Type="int64" Nullable="false" />
                    <Property Name="OWNER_ID" Type="VARCHAR2" Nullable="false" MaxLength="30" />
                    <Property Name="EQUIPMENT_ID" Type="VARCHAR2" MaxLength="100" />
                </EntityType>
            </Schema></edmx:StorageModels>
        <!-- CSDL content -->
        <edmx:ConceptualModels>
            <Schema Namespace="DataAccess.SD" Alias="Self" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns="http://schemas.microsoft.com/ado/2008/09/edm">
                <EntityContainer Name="SDContext" annotation:LazyLoadingEnabled="true">
                    <EntitySet Name="Customers" EntityType="DataAccess.SD.Customer" />
                    <EntitySet Name="Trailers" EntityType="DataAccess.SD.Trailer" />
                </EntityContainer>
                <EntityType Name="Customer">
                    <Key>
                        <PropertyRef Name="Id" />
                    </Key>
                    <Property Name="Id" Type="Int64" Nullable="false" />
                    <Property Name="Name" Type="String" MaxLength="40" Unicode="false" FixedLength="false" />
                    <Property Name="AccNo" Type="String" MaxLength="20" Unicode="false" FixedLength="false" />
                    </EntityType>
                <EntityType Name="Trailer">
                    <Key>
                        <PropertyRef Name="Id" />
                    </Key>
                    <Property Type="Int64" Name="Id" Nullable="false" />
                    <Property Type="String" Name="Number" MaxLength="100" FixedLength="false" Unicode="false" />
                    <Property Type="String" Name="Customer_Id" Nullable="false" MaxLength="30" 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="SDModelsStoreContainer" CdmEntityContainer="SDContext">
                    <EntitySetMapping Name="Customers">
                        <EntityTypeMapping TypeName="DataAccess.SD.Customer">
                            <MappingFragment StoreEntitySet="CUSTOMER">
                                <ScalarProperty Name="Id" ColumnName="CUSTOMEROID" />
                                <ScalarProperty Name="Name" ColumnName="CUSTOMER_NAME" />
                                <ScalarProperty Name="AccNo" ColumnName="CUSTOMER_ACCOUNT" />
                                </MappingFragment>
                        </EntityTypeMapping>
                    </EntitySetMapping>
                    <EntitySetMapping Name="Trailers">
                        <EntityTypeMapping TypeName="DataAccess.SD.Trailer">
                            <MappingFragment StoreEntitySet="EQUIPMENT">
                                <ScalarProperty Name="Number" ColumnName="EQUIPMENT_ID" />
                                <ScalarProperty Name="Customer_Id" ColumnName="OWNER_ID" />
                                <ScalarProperty Name="Id" ColumnName="EQUIPMENTOID" />
                            </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/2008/10/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="True" />
            </DesignerInfoPropertySet>
        </Options>
        <!-- Diagram content (shape and connector positions) -->
        <Diagrams>
            <Diagram Name="SD" ZoomLevel="100">
                <EntityTypeShape EntityType="DataAccess.SD.Customer" Width="1.75" PointX="0.75" PointY="0.75" Height="1.59568359375" IsExpanded="true" />
                <EntityTypeShape EntityType="DataAccess.SD.Trailer" Width="1.75" PointX="3.125" PointY="0.75" Height="1.59568359375" />
                <AssociationConnector Association="DataAccess.SD.CustomerTrailer">
                    <ConnectorPoint PointX="2.5" PointY="1.7064925130208335" />
                    <ConnectorPoint PointX="4" PointY="1.7064925130208335" />
                </AssociationConnector>
                <AssociationConnector Association="DataAccess.SD.CustomerTrailer">
                    <ConnectorPoint PointX="2.5" PointY="1.6439925130208335" />
                    <ConnectorPoint PointX="3.125" PointY="1.6439925130208335" />
                </AssociationConnector>
            </Diagram>
        </Diagrams>
    </Designer>
</edmx:Edmx>


我到底需要做什么?

在edmx设计器中,您只需右键单击并选择“添加新>>关联”。确保取消选中“添加外键属性…”选项,并选择所需的实体和导航属性名称


然后选择关联,并在“属性”窗格中单击“引用约束”选项-在此可以设置关联中涉及的字段。您还需要在“属性”窗格中设置正确的多重性。

非常感谢,您的解决方案本来可以工作,但在我的情况下,类型似乎不匹配,一个是int64,另一个是字符串(即使它包含数字):`(该死的DBA。我无法将它们与这种不匹配联系起来。