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:
- Opened the
.edmx
file in Visual Studio Code;
- Searched for the offending
table_name
;
- Added the missing mappings where appropriate.
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.