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:
- Edited the
.edmx
file in Visual Studio Code;
- Looked for
custom_table
;
- 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>