I’m trying to find the ComplexType that’s mapped to my FunctionImport from my MetadataWorkspace.
The related xml is there in the CSSpace of the edmx, but I can’t figure out how to get it out.
I can go for the EdmFunction itself from the SSpace, but that doesn’t tell me the ComplexType that it’s mapped to, does it? I can also go for the ComplexType itself in the CSpace, but that doesn’t tell me the FunctionImport it’s mapped to…
The related xml in the edmx is:
<FunctionImportMapping FunctionImportName="GetContactsByName" FunctionName="Test2Model.Store.GetContactsByName">
<ResultMapping>
<ComplexTypeMapping TypeName="Test2Model.GetContactsByName_Result">
<ScalarProperty Name="FirstName" ColumnName="FirstName" />
<ScalarProperty Name="LastName" ColumnName="LastName" />
<ScalarProperty Name="Address1" ColumnName="Address1" />
<ScalarProperty Name="Address2" ColumnName="Address2" />
<ScalarProperty Name="City" ColumnName="City" />
<ScalarProperty Name="StateID" ColumnName="StateID" />
<ScalarProperty Name="Country" ColumnName="Country" />
</ComplexTypeMapping>
</ResultMapping>
</FunctionImportMapping>
At runtime I can get a the StorageEntityMappingCollection but I’m not sure where to go from there:
((System.Data.Mapping.StorageMappingItemCollection)
metadataWorkspace.GetItemCollection(DataSpace.CSSpace)).First() // then what....all I see after this is a bunch of MetadataProperties which seem to take me in circles...
According to various sources, pretty much all of the CSSpace is completely internalized and unaccessible to the developer. I saw recommendations that I should go straight for the mapping xml, but I really didn’t want to do that…So ultimately I came up with this solution which seems to work well for getting out all of the mappings from an ObjectContext.
Note…this is expensive…so if someone else finds this helpful and takes this approach, they should make sure to cache it.