none
Error message 3007 Entity Framework 3.5

    Question

  • Hi together,

    I have a problem and i can't solve it. I get the following Error message:

    error 3007: Problem in Mapping Fragments starting at lines 6, 69: Non-Primary-Key column(s) [CALENDAR_ID] are being mapped in both fragments to different conceptual side properties - data inconsistency is possible because the corresponding conceptual side properties can be independently modified.

    My edmx-file looks line this:

    Code Snippet

    <?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="ORMPerformanceTestTool.Data.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2000" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2006/04/edm/ssdl">
            <EntityContainer Name="ORMPerformanceTestToolDataStoreContainer">
              <EntitySet Name="Appointments" EntityType="ORMPerformanceTestTool.Data.Store.Appointments" store:Type="Tables" Schema="dbo" />
              <EntitySet Name="Calendars" EntityType="ORMPerformanceTestTool.Data.Store.Calendars" store:Type="Tables" Schema="dbo" />
            </EntityContainer>
            <EntityType Name="Appointments">
              <Key>
                <PropertyRef Name="ID" />
              </Key>
              <Property Name="ID" Type="int" Nullable="false" StoreGeneratedPattern="Identity" />
              <Property Name="DATECREATE" Type="datetime" />
              <Property Name="DATEMODIFIED" Type="datetime" />
              <Property Name="CREATEDBY" Type="nvarchar" MaxLength="20" />
              <Property Name="OWNER" Type="nvarchar" MaxLength="20" />
              <Property Name="PROCESSOR" Type="nvarchar" MaxLength="255" />
              <Property Name="CALENDAR_ID" Type="int" />
    ....
            </EntityType>
            <EntityType Name="Calendars">
              <Key>
                <PropertyRef Name="ID" />
              </Key>
              <Property Name="ID" Type="int" Nullable="false" StoreGeneratedPattern="Identity" />
              <Property Name="DATECREATE" Type="datetime" />
    ...
            </EntityType>
          </Schema>
        </edmx:StorageModels>
        <!-- CSDL content -->
        <edmx:ConceptualModels>
          <Schema Namespace="ORMPerformanceTestTool.Data" Alias="Self" xmlns="http://schemas.microsoft.com/ado/2006/04/edm">
            <EntityContainer Name="AppointmentsAndCalendarsDAO">
              <EntitySet Name="Appointments" EntityType="ORMPerformanceTestTool.Data.Appointments" />
              <EntitySet Name="Calendars" EntityType="ORMPerformanceTestTool.Data.Calendars" />
              <AssociationSet Name="CalendarsAppointments" Association="ORMPerformanceTestTool.Data.CalendarsAppointments">
                <End Role="Calendars" EntitySet="Calendars" />
                <End Role="Appointments" EntitySet="Appointments" /></AssociationSet></EntityContainer>
            <EntityType Name="Appointments">
              <Key>
                <PropertyRef Name="ID" />
              </Key>
              <Property Name="ID" Type="Int32" Nullable="false" />
              <Property Name="DATECREATE" Type="DateTime" />
              <Property Name="DATEMODIFIED" Type="DateTime" />
              <Property Name="CREATEDBY" Type="String" MaxLength="20" Unicode="true" FixedLength="false" />
              <Property Name="OWNER" Type="String" MaxLength="20" Unicode="true" FixedLength="false" />
              <Property Name="PROCESSOR" Type="String" MaxLength="255" Unicode="true" FixedLength="false" />
              <Property Name="CALENDAR_ID" Type="Int32" />
    ...
              <NavigationProperty Name="Calendars" Relationship="ORMPerformanceTestTool.Data.CalendarsAppointments" FromRole="Appointments" ToRole="Calendars" /></EntityType>
            <EntityType Name="Calendars">
              <Key>
                <PropertyRef Name="ID" />
              </Key>
              <Property Name="ID" Type="Int32" Nullable="false" />
              <Property Name="DATECREATE" Type="DateTime" />
    ...
              <NavigationProperty Name="Appointments" Relationship="ORMPerformanceTestTool.Data.CalendarsAppointments" FromRole="Calendars" ToRole="Appointments" /></EntityType>
            <Association Name="CalendarsAppointments">
              <End Type="ORMPerformanceTestTool.Data.Calendars" Role="Calendars" Multiplicity="1" />
              <End Type="ORMPerformanceTestTool.Data.Appointments" Role="Appointments" Multiplicity="*" /></Association></Schema>
        </edmx:ConceptualModels>
        <!-- C-S mapping content -->
        <edmx:Mappings>
          <Mapping Space="C-S" xmlns="urn:schemas-microsoft-com:windows:storage:mapping:CS">
            <EntityContainerMapping StorageEntityContainer="ORMPerformanceTestToolDataStoreContainer" CdmEntityContainer="AppointmentsAndCalendarsDAO">
              <EntitySetMapping Name="Appointments">
                <EntityTypeMapping TypeName="IsTypeOf(ORMPerformanceTestTool.Data.Appointments)">
                  <MappingFragment StoreEntitySet="Appointments">
                    <ScalarProperty Name="ID" ColumnName="ID" />
                    <ScalarProperty Name="DATECREATE" ColumnName="DATECREATE" />
                    <ScalarProperty Name="DATEMODIFIED" ColumnName="DATEMODIFIED" />
                    <ScalarProperty Name="CREATEDBY" ColumnName="CREATEDBY" />
                    <ScalarProperty Name="OWNER" ColumnName="OWNER" />
                    <ScalarProperty Name="PROCESSOR" ColumnName="PROCESSOR" />
                    <ScalarProperty Name="CALENDAR_ID" ColumnName="CALENDAR_ID" />
    ...
                  </MappingFragment>
                </EntityTypeMapping>
              </EntitySetMapping>
              <EntitySetMapping Name="Calendars">
                <EntityTypeMapping TypeName="IsTypeOf(ORMPerformanceTestTool.Data.Calendars)">
                  <MappingFragment StoreEntitySet="Calendars">
                    <ScalarProperty Name="ID" ColumnName="ID" />
                    <ScalarProperty Name="DATECREATE" ColumnName="DATECREATE" />
    ....
                  </MappingFragment>
                </EntityTypeMapping>
              </EntitySetMapping>
              <AssociationSetMapping Name="CalendarsAppointments" TypeName="ORMPerformanceTestTool.Data.CalendarsAppointments" StoreEntitySet="Appointments">
                <EndProperty Name="Appointments">
                  <ScalarProperty Name="ID" ColumnName="ID" /></EndProperty>
                <EndProperty Name="Calendars">
                  <ScalarProperty Name="ID" ColumnName="CALENDAR_ID" /></EndProperty></AssociationSetMapping></EntityContainerMapping>
          </Mapping>
        </edmx:Mappings>
      </edmx:Runtime>
      <!-- EF Designer content (DO NOT EDIT MANUALLY BELOW HERE) -->
      <edmx:Designer xmlns="http://schemas.microsoft.com/ado/2007/06/edmx">
        <edmx:Connection>
          <DesignerInfoPropertySet>
            <DesignerProperty Name="MetadataArtifactProcessing" Value="EmbedInOutputAssembly" />
          </DesignerInfoPropertySet>
        </edmx:Connection>
        <edmx:Options>
          <DesignerInfoPropertySet>
            <DesignerProperty Name="ValidateOnBuild" Value="true" />
          </DesignerInfoPropertySet>
        </edmx:Options>
        <!-- Diagram content (shape and connector positions) -->
        <edmx:Diagrams>
          <Diagram Name="AppointmentsAndCalendars" ZoomLevel="94">
            <EntityTypeShape EntityType="ORMPerformanceTestTool.Data.Appointments" Width="1.5" PointX="0.75" PointY="0.75" Height="9.67234375" IsExpanded="true" />
            <EntityTypeShape EntityType="ORMPerformanceTestTool.Data.Calendars" Width="1.5" PointX="2.75" PointY="0.75" Height="2.5571907552083335" IsExpanded="true" />
            <AssociationConnector Association="ORMPerformanceTestTool.Data.CalendarsAppointments">
              <ConnectorPoint PointX="2.75" PointY="2.0285953776041667" />
              <ConnectorPoint PointX="2.25" PointY="2.0285953776041667" /></AssociationConnector></Diagram></edmx:Diagrams>
      </edmx:Designer>
    </edmx:Edmx>



    Pleas can somebody help my what I must to take to solve this problem?

    Thanks
    Ahmet
    Wednesday, November 05, 2008 10:48 AM

Answers

  • You are mapping CalendarId to both an entitytype property and an association end. Since this would allow the independent modification of the values, thus creating conflicts at update time, the EF, for now, disallows this.

     

    The solution is to remove calendarId from your entitytype.

     

    Wednesday, November 05, 2008 7:34 PM
    Moderator

All replies

  • You are mapping CalendarId to both an entitytype property and an association end. Since this would allow the independent modification of the values, thus creating conflicts at update time, the EF, for now, disallows this.

     

    The solution is to remove calendarId from your entitytype.

     

    Wednesday, November 05, 2008 7:34 PM
    Moderator
  • Thank you Noam Ben-Ami,

    your answer was very helpful
    Wednesday, November 12, 2008 5:51 PM
  • The answer was helpful but the feature is not. Let the developer keep track of inconsistencies that may occur, the usefulness is degraded alot by restrictions like this.

    /Ragnar
    Monday, November 17, 2008 10:58 AM
  • HI

     

    I am using the SP1 version and encounter the same problem

     

    If the framework is to be of any use to me I must be able to Map the entire db . . If this mapping error specifically disallows tables , it makes the entire mapping process of little use , to use a framwork to create a data layer surely all normal SQL tables must be usable. To disallow some negates the whole .

     

    The tables in question are simple tables Material with MaterialID as a PK , MaterialType with MaterialTypeID as a PK and MaterialMaster with MaterialMasterID as a PK.

     

    The Material Table has 1:* FK to MaterialMasterID , and again to MaterialTypeID . It would seem (to me) a simple and logical design to normalise these things out.

     

    I can create a Linq_SQL designer with no problem and derive the same associtaiosn so why not in the Entity Framework.

     

    I have persevered and have got progress with the framework even though some of its logic seems a touch obscure, but this restriction will not help my specific progress to using the framwork

     

    Is there a workaround ??

     

    As an aside , is there help files available for the SP1 extras , as I only seem to be able to get individual help on line , I can't seem to find a download of MSDN or the upgrade bits for SP1

     

    Cheers

     

    Mike

     

    Tuesday, December 02, 2008 5:32 AM
  • PS

     

    I think I understand the error now ,i that the Materials entity collection can be a collection of any one of the two tables hence the clash

     

    Does this mean that to be of use , you can only have on FK Constraint per table

     

    If there are 2 , can you delete on in the Model Designer to make the model bleieve there is only one whilst keeping teh COnstraint in SQL

    Tuesday, December 02, 2008 11:45 AM
  • Just learning here but my experience might be relevant.

     

    Got this error after:

    - Creating model from an existing database

    - Added a foreign key to the database

    - Updated the model

     

    When the model was first created my 'user' entity had a 'defaultunitid' property (mapped to the defaultunitid' column in the database).

    The foreign key I added was a link to my 'unit' table via the defaultunitid column.

    After updating the model I noticed that the 'user' entity still had the defaultunitid property even though it now also had a 'unit' Navigation Property.

    The error was resolved for me by deleting the defaultunitid property from my 'user' entity.

    note: This is ok because the defaultunitid mapping from my entity to the database is still defined (within in the Navigation Property).

    Thursday, January 29, 2009 9:28 PM
  • Just learning here but my experience might be relevant.

     

    Got this error after:

    - Creating model from an existing database

    - Added a foreign key to the database

    - Updated the model

     

    When the model was first created my 'user' entity had a 'defaultunitid' property (mapped to the defaultunitid' column in the database).

    The foreign key I added was a link to my 'unit' table via the defaultunitid column.

    After updating the model I noticed that the 'user' entity still had the defaultunitid property even though it now also had a 'unit' Navigation Property.

    The error was resolved for me by deleting the defaultunitid property from my 'user' entity.

    note: This is ok because the defaultunitid mapping from my entity to the database is still defined (within in the Navigation Property).

    I had the same problem. Try this :

    1. Verify the FK field  if check to  not allow null on your database.

    2. Refresh the relation on the Entity Model. (In my case, I delete the Model and recreated).

     

    Thursday, March 25, 2010 3:49 PM
  •  

    Agree! What realy matters: Database or DataContext?

     

    I think is database...

    Tuesday, November 16, 2010 10:26 PM
  • Hi Guys,

    I've got this problem, however that it refers to for me is AssessmentID, yet I have quite a few Tables in the EF that have a foreign key called AssessmentID.  

    The Line/Column numbers seemed to refer to the opening <AssociationSetMapping> tag in my Model.Designer.cs file:

    <AssociationSetMapping Name="FK_UserAssessment_Assessments" TypeName="P42Model.FK_UserAssessment_Assessments" StoreEntitySet="UserAssessment">
    
                <EndProperty Name="UserAssessment">
                  <ScalarProperty Name="ID" ColumnName="ID" />
                </EndProperty>
                <EndProperty Name="Assessment">
                  <ScalarProperty Name="ID" ColumnName="AssessmentID" />
                </EndProperty>
              </AssociationSetMapping>

    So I deleted the two entities: UserAssessment and Assessment, recompiled (errors) then added them back in.

    Seemed to resolve the problem.

    Friday, June 22, 2012 4:27 PM