开发者

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

Closed. This question needs debugging details. It is not currently accepting answers.

Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.

Closed 3 years ago.

开发者_如何学C Improve this question

I have this error when I build my Web Service:

Error 3004: Problem in mapping fragment starting at line 323: No mapping specified for properties JE_TRN_HS.JE_HDR_HSJE_HDR_KEY. Entity is type [TESTCPModel.JE_TRN_HS

This is what happend. I created this Entity Data Model from an existing database. I added 2 tables and rebuilt the Web Service. The build was successfull.

THEN I added an Association between the two tables. When I tried to rebuild it failed with the error message displayed above!

Now here's the kicker! I deleted the newly added Association and rebuilt. The build failed with the same error message!? The only way I can get rid of this error is if I delete the second table, rebuild and re-add the second table??

I've looked EVERYWHERE for the solution to this problem! Thanks Steve


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>


You cannot simply add tables from the database into your model and then create a new association in the model. By default it uses independent association which must be mapped to its database counterpart = the relation must exists in the database as well. You must model your relation as FK association but it allows only one-to-one and one-to-many associations. Differences between association types are described here.


I've had this problem when i ended up 'updating model from database' after having changed the connection string.

By right clicking the entity and toggling a key on and off It seems to have caused a refresh and has fixed the problem. This seems more like a bug with the Entity framework.

It should be noted in this case i was using the MySQL connector so I suspect it's just rather finicky in general.


You can get this error if you have a property on the model that isn't mappable.

For instance I was converting some Linq2Sql over to EF6 and had an error on a Binary field. Binary is a System.Data.Linq type but for EF it needs to be byte[]. Changing it fixed the problem.


Experienced a similar problem with EF 6:

exception.InnerException
{"\r\nEntities.EAM.msl(458,10) : error 3004: Problem in mapping fragments starting at line 458:No mapping specified for properties InspectionPdfReportRequest.SyncDate in Set InspectionPdfReportRequests.\r\nAn Entity with Key (PK) will not round-trip when:\r\n  Entity is type [Model.Entities.InspectionPdfReportRequest]\r\n\r\nEntities.EAM.msl(488,10) : error 3004: Problem in mapping fragments starting at line 488:No mapping specified for properties InspectionReportRequest.SyncDate in Set InspectionReportRequests.\r\nAn Entity with Key (PK) will not round-trip when:\r\n  Entity is type [Model.Entities.InspectionReportRequest]\r\n"}
    Data: {System.Collections.ListDictionaryInternal}
    HResult: -2146232032
    HelpLink: null
    InnerException: null

The problem turned out to be that I had made a change to the *.edmx file for my database-first EF application directly in a text editor instead of using the designer. So just reverted the text changes and applied them using the designer and the error went away. Hitting save in the designer is what updated the associated *.msl file.


I was getting this error from Linqpad and could not figure out why it started happening all of a sudden and whether this would be an issue in my application using the context. I also just deleted the class that was recently created by a new entity and then I right clicked on the .tt file and hit "run to cursor" to regenerate the class. That fixed it for me.


Updating Model from Database option doesn't work for me.

So I need to delete all entities first before updating model from database to successfully fix the solution.


If you have applied a mapping on the entity, try to remove that column from the table which will resolve the issue


In my case, my database administrator has changed column names from uppercase to lower. I solved the problem by updating (update model from database) for that table again. Then, deleted previous uppercase columns.


In my case, I had renamed a field in a table and added a primary key. After that, I got that error. I went to my list of objects/models and after delete it and refresh from the database, I had again the same error. I tried several times but nothing. The class that EF was generating was a mix between the old table structure and the new one.

After investigating for a while, this is the solution: Go to the Diagram of your your entities. Locate your table or open on your right the Model Explorer (right click over the diagram - Open model explorer). Search for your model/table under ...Model, ...Model.Store and delete it. After that, add again the table from the database and problem solved.


in my case,in solution at first I refreshed MyProjectname.edmx file but it didn't work .Then I deleted the table that I had modified it and again updated the Model form database (not refresh it).And it works.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜