Hi,
I'm trying to create a new Layer from a table which is the result of a join between a FeatureClass and a table. I used the following example as a basis (specifically the "MakeJoin"-Function from "JoinsDockPaneViewModel.cs"):
https://github.com/Esri/arcgis-pro-sdk-community-samples/tree/master/Geodatabase/DynamicJoins
The FeatureClass comes from a file geodatabase, the table from a postgreSQL database that is not an enterprise geodatabase. My code looks like this:
private RelationshipClass MakeJoin(RelationshipClass relationshipClass, Table leftTable, Table rightTable, Field leftField, Field rightField, string layername)
{
VirtualRelationshipClassDescription virtualRelationshipClassDescription = new VirtualRelationshipClassDescription(leftField, rightField, RelationshipCardinality.OneToOne);
relationshipClass = leftTable.RelateTo(rightTable, virtualRelationshipClassDescription);
JoinDescription joinDescription = new JoinDescription(relationshipClass)
{
JoinDirection = JoinDirection.Forward,
JoinType = JoinType.InnerJoin,
TargetFields = leftTable.GetDefinition().GetFields()
};
Join join = new Join(joinDescription);
Table joinedTable = join.GetJoinedTable();
if (joinedTable is FeatureClass)
{
FeatureClass joinedFc = (FeatureClass) joinedTable;
FeatureLayerCreationParams layerParams = new FeatureLayerCreationParams(joinedFc);
LayerFactory.Instance.CreateLayer<FeatureLayer>(layerParams, MapView.Active.Map);
}
return relationshipClass;
}
At line 19 (CreateLayer) the following Exception occurs:
A user-supplied component or subscriber raised an exception (0x80040208)
System.ArgumentException
Quelle: ArcGIS.Desktop.Mapping
TargetSite: T MakeBasicServiceCall[T](System.Func`1[T])
Stack:
at ArcGIS.Desktop.Internal.Mapping.Utilities.MakeBasicServiceCall[T](Func`1 serviceCall)
at ArcGIS.Desktop.Mapping.LayerCreationParams.CreateFromDataConnection(ILayerContainerEdit mapOrGroupLayer, Int32 index)
at ArcGIS.Desktop.Mapping.LayerCreationParams.CreateLayer(ILayerContainerEdit mapOrGroupLayer, Int32 layerIndex)
at ArcGIS.Desktop.Mapping.LayerFactory.CreateLayer[T](LayerCreationParams layerParams, ILayerContainerEdit container)
InnerException:
A user-supplied component or subscriber raised an exception (0x80040208)
System.Runtime.InteropServices.COMException
Quelle: ArcGIS.Desktop.Mapping
TargetSite: System.String AddData(ArcGIS.Desktop.Internal.Mapping.CreateLayerArgs ByRef, System.String)
Stack:
at ArcGIS.Desktop.Internal.DesktopService._IMapAuthoringService.AddData(CreateLayerArgs& args, String dataConnectionXml)
at ArcGIS.Desktop.Mapping.Map.<>c__DisplayClass316_0.<AddData>b__0()
at ArcGIS.Desktop.Internal.Mapping.Utilities.MakeBasicServiceCall[T](Func`1 serviceCall)
The exception doesn't occur when I use two FeatureClasses to create the join.
Is there something that I'm missing in my code? Is there maybe another way to create a join with a FeatureLayer and a table? Using the Geoprocessing Tool is no option for me.
I'm using the ArcGIS Pro SDK for .NET 3.1.
Thanks in advance.
Hello again,
does anyone have a guess about what I'm missing here? I'm stuck with this currently and I can't figure out why. Any help would be appriciated.
Just in case this is still pending...in my case I needed to switch to a LeftOuterJoin for the join type.