Reputation: 3813
To improve an older project I am forced by the circumstances to use VS 2008 and Framework 3.5 - I have issues with the edmx showing bizarre behavior and not updating the entities as required.
The edmx throws me the above error, but when I go to the respective table and right click it - "Update Model from Database" there is no change, the error is still there.
If I delete the table from the diagram by selecting it and pressing del, then in the Model Browser It disappears from the .Database but when clicking "Update model from Database" I can't see i in the "Add" list, all I can do is "Refresh" the table since I still see it in the refresh list (which should not happen because I deleted it! )
Upvotes: 64
Views: 101678
Reputation: 1
Try to mape it in the xml file of your model :
<ScalarProperty Name="CampaignKey" ColumnName="CampaignKey" />
It works for me.
Upvotes: 0
Reputation: 254
when you change the name of your column and try to update to the database, it loses its mapping.
Solution:
1- right-click on the table that has property not mapped at.
2- select the table mapping option.
3- you will find the not mapped property doesn't have mapping.
Upvotes: 1
Reputation: 21
Entity Framework error - Error 11009: Property is not mapped
The reason for this error is there is no proper sync between the DB and the .edmx file.
Solution 1
Delete the model from the .edmx file and add it again.
Solution 2
Edit the .edmx file by right clicking it.
Add the updated/new property at the two following places;
Under:
<EntityType Name="TableName">
<Property Name="SaleFinYear" Type="varchar" MaxLength="50" />
Under`:
<MappingFragment StoreEntitySet="TableName">
<ScalarProperty Name="SaleFinYear" ColumnName="SaleFinYear" />
For more details with screenshots check - here
Upvotes: 0
Reputation: 6591
The easiest way I've found to deal with this is to find the model/table with the unmapped property in the edmx. Select it and delete it. Save your edmx and then update it again, adding the model back in from the database. Deleting just the unmapped property didn't work for me.
Upvotes: 2
Reputation: 102438
In my case I added a new scalar property named sys_user_id
to an existing table in the Designer inside Visual Studio. I didn't update the Model from the Database because that was causing a lot of errors in the designer. I just wanted to map a single column that was added to a given table on the database side.
The problem is that after doing this I started getting the following exception:
- InnerException {"\r\nModels.ShardData.msl(352,10) : error 3004: Problem in mapping fragments starting at line 352: No mapping specified for properties table_name.sys_user_id in Set table_name.\r\nAn Entity with Key (PK) will not round-trip when:\r\n Entity is type [ShardDB.table_name]\r\n"} System.Exception {System.Data.Entity.Core.MappingException}
In Visual Studio what was being shown in the Error List
window was: Error 11009: Property ' ' is not mapped
What I did to fix this was the following:
.edmx
file in Visual Studio Code;table_name
;It was missing the mappings in 2 places:
<EntityType Name="table_name">
<Key>
<PropertyRef Name="user_id" />
</Key>
<Property Name="user_id" Type="int" Nullable="false" />
<Property Name="tenant_id" Type="int" />
... ALL OTHER COLUMNS HERE ...
<Property Name="sys_user_id" Type="int" Nullable="true" /> <= WAS MISSING THIS AND SO I HAD TO ADD IT BY HAND
</EntityType>
and
<EntitySetMapping Name="table_name">
<EntityTypeMapping TypeName="ShardDB.table_name">
<MappingFragment StoreEntitySet="table_name">
<ScalarProperty Name="user_id" ColumnName="user_id" />
<ScalarProperty Name="tenant_id" ColumnName="tenant_id" />
... ALL OTHER COLUMNS HERE ...
<ScalarProperty Name="sys_user_id" ColumnName="sys_user_id" /> <= WAS MISSING THIS AND SO I HAD TO ADD IT BY HAND
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>
After changing it in Visual Studio Code and getting back to Visual Studio it asked me to reload the .edmx
file since it was modified. Reloaded and then hit F5 to run the code. It started working as expected.
Upvotes: 2
Reputation: 616
I have this error (Error 3007: Problem in mapping fragments starting at lines ... ) , after add a table to .edmx
First I delete the last added table, then I re-update the model wiht that table, but checking the 'include foreing key checkbox:
Upvotes: 0
Reputation: 1580
I had the same issue with Visual Studio 2017 and Entity Framework 6 on a Database First model, upon refreshing it to get new columns.
I tried everything above but the only thing that worked was to delete the EDMX and generate a new one.
Upvotes: 0
Reputation: 167
I know this question was about VS 2008 and 'recovering' a model, but for anyone who finds this like I did when I had the same Error 11009 in VS 2015, I first tried the "Update Model from Database" to no avail, then I finally fixed it by right-clicking the model table in the .edmx design and choosing Table Mapping. I did not have to delete the model. My model is associated with a db table.
Upvotes: 3
Reputation: 1088
I had this issue when I changed a column name from CampaignKey
to CampaignCode
. After making the DB change, I went to the .edmx
designer, right clicked and chose Update Model from Database. Then when I compiled I got the error:
Error 11009: Property
CampaignKey
is not mapped.
Taking a closer look at my table in the designer showed me that Visual Studio had created the new field CampaignCode
as in the DB. But it also had left the old field CampaignKey
in there, causing the error as it no longer exists in the DB.
To fix the issue, I right-clicked on the CampaignKey
field in my table in the designer and selected Delete.
After that I saved the .edmx
, compiled and the error was gone.
Upvotes: 56
Reputation: 6638
Check the xml file of your model, it's probably still in there somewhere. Try deleting it manually from that XML file, then try to update again. Be sure to take backups though.
Upvotes: 55
Reputation: 3026
I had the same error when I changed a column name in the database and updated the database from the model. I was unable to find the original name anywhere in the solution. I solved it by simply
Upvotes: 1
Reputation: 226
I opened the edmx file in Notepad and deleted the incorrect field. I then updated the model again in the designer
Upvotes: 3
Reputation: 3403
I have gotten this same error before when column names on tables or views change case. For example, if a view has a column named "OrderID" and then the column name is changed to "OrderId" then it will give the error 'Property "OrderID" is not mapped'. This can be resolved by changing the case back to how it exists in the model.
Upvotes: 3
Reputation: 1014
At times, upgrading a project throws up errors.
Just make sure you have backed up all your data, just-in-case.
When we add entity model into our project, it adds a corresponding connection string to web.config. Now, when you delete the model from project, even then the connection string still resides there in the web.config.
So, take the following steps:
Hopefully, it should work.
Upvotes: 2