Error 3004: Problem in mapping fragment starting at line [closed] Error 3004: Problem in mapping fragment starting at line [closed] database database

Error 3004: Problem in mapping fragment starting at line [closed]


In my case am not allowed to modify existing tables but I discovered that when you add a new table with "Include foreign key columns in the model" checked in EF4 and the table doesn't contain any foreign key relationships then you try to add a association it will trigger this error.

Defining Constraints in an EF4 model that don’t exist in the database


In case the linked article disappears, The solution is:

You need to open the properties window of the association and then click on the Referential Constraint ellipses to get to the ref constraint dialog. Then select the correct field for the 'Dependent Property' setting.


In my case, another developer had deleted the field from the table in the database. Having realised this, removing the table from the entity model and adding it back solved the problem.


I hit this problem right now... Needed to add a scalar property, let's say custom_property to an existing table using the Designer in Visual Studio.

I could've updated the Model from the Database but that was not an option. It was causing a lot of errors in the Model. It's a huge database model and the table I needed to add this property has maybe more than 30 relationships. I just wanted to map this new custom_property column that got added to the table named custom_table.

After adding the scalar property directly in the designer, the following exception was being thrown:

  • InnerException {"\r\nModels.MyDB.msl(352,10) : error 3004: Problem in mapping fragments starting at line 352: No mapping specified for properties custom_table.custom_property in Set custom_table.\r\nAn Entity with Key (PK) will not round-trip when:\r\n Entity is type [MyDB.custom_table]\r\n"} System.Exception {System.Data.Entity.Core.MappingException}

In the Error List in VS this was being shown: Error 11009: Property ' ' is not mapped

Steps I took to fix this:

  1. Edited the .edmx file in Visual Studio Code;
  2. Looked for custom_table;
  3. Complemented the .edmx XML code with mappings.

These were the places where I had to add mappings:

<EntityType Name="custom_table">    <Key>        <PropertyRef Name="some_id" />    </Key>    <Property Name="some_id" Type="int" Nullable="false" />    <Property Name="other_id" Type="int" />    ...    <Property Name="custom_property" Type="int" Nullable="true" /> <= THIS WAS ADDED BY ME</EntityType>

and

<EntitySetMapping Name="custom_table">  <EntityTypeMapping TypeName="MyDB.custom_table">    <MappingFragment StoreEntitySet="custom_table">      <ScalarProperty Name="some_id" ColumnName="some_id" />      <ScalarProperty Name="other_id" ColumnName="other_id" />      ...      <ScalarProperty Name="custom_property" ColumnName="custom_property" /> <= THIS WAS ADDED BY ME    </MappingFragment>  </EntityTypeMapping></EntitySetMapping>