1

在我的 DAL 项目中添加了数据库和实体模型。

有一个错误:

错误 :

 +      base    {"Schema specified is not valid. Errors: \r\nMultiple types with the name 'TblRecord' exist in the EdmItemCollection in different namespaces.  Convention based mapping requires unique names without regard to namespace in the EdmItemCollection."}   System.Data.EntityException {System.Data.MetadataException}

Edmx 文件

<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="3.0" xmlns:edmx="http://schemas.microsoft.com/ado/2009/11/edmx">
  <!-- EF Runtime content -->
  <edmx:Runtime>
    <!-- SSDL content -->
    <edmx:StorageModels>
      <Schema Namespace="Xz.Business.Matches.Store" Alias="Self" Provider="System.Data.SqlServerCe.4.0" ProviderManifestToken="4.0" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2009/11/edm/ssdl">
        <EntityContainer Name="XzBusinessMatchesStoreContainer">
          <EntitySet Name="Records" EntityType="Xz.Business.Matches.Store.Records" store:Type="Tables" />
        </EntityContainer>
        <EntityType Name="Records">
          <Key>
            <PropertyRef Name="Record" />
          </Key>
          <Property Name="Record" Type="nvarchar" Nullable="false" MaxLength="100" />
          <Property Name="Relations" Type="nvarchar" MaxLength="450" />
        </EntityType>
      </Schema>
    </edmx:StorageModels>
    <!-- CSDL content -->
    <edmx:ConceptualModels>
      <Schema Namespace="Xz.Business.Matches" Alias="Self" p1:UseStrongSpatialTypes="false" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns:p1="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns="http://schemas.microsoft.com/ado/2009/11/edm">
        <EntityContainer Name="RecordzEntities" p1:LazyLoadingEnabled="true">
          <EntitySet Name="Records" EntityType="Xz.Business.Matches.TblRecord" />
        </EntityContainer>
        <EntityType Name="TblRecord">
          <Key>
            <PropertyRef Name="Record" />
          </Key>
          <Property Name="Record" Type="String" Nullable="false" MaxLength="100" Unicode="true" FixedLength="false" />
          <Property Name="Relations" Type="String" MaxLength="450" Unicode="true" FixedLength="false" />
        </EntityType>
      </Schema>
    </edmx:ConceptualModels>
    <!-- C-S mapping content -->
    <edmx:Mappings>
      <Mapping Space="C-S" xmlns="http://schemas.microsoft.com/ado/2009/11/mapping/cs">
        <EntityContainerMapping StorageEntityContainer="XzBusinessMatchesStoreContainer" CdmEntityContainer="RecordzEntities">
          <EntitySetMapping Name="Records">
            <EntityTypeMapping TypeName="Xz.Business.Matches.TblRecord">
              <MappingFragment StoreEntitySet="Records">
                <ScalarProperty Name="Record" ColumnName="Record" />
                <ScalarProperty Name="Relations" ColumnName="Relations" />
              </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/2009/11/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" />
        <DesignerProperty Name="CodeGenerationStrategy" Value="None" />
      </DesignerInfoPropertySet>
    </Options>
    <!-- Diagram content (shape and connector positions) -->
    <Diagrams></Diagrams>
  </Designer>
</edmx:Edmx>

名称和命名空间:

项目名称:Business.Matches 默认命名空间:Xz.Business.Matches

我添加了一个具有以下定义的实体模型:

型号:RecordzModel

上下文:RecordzContext

模型命名空间:Xz.Business.Matches

4

1 回答 1

3

您的项目中似乎有不止一门名为“TblRecord”的课程。将您的类型与 POCO 类型的 EDM 类型匹配时,名称空间将被忽略,因此如果您有多个具有相同名称的类,则它会模棱两可并导致异常。

于 2012-10-19T19:16:07.247 回答