Select to view content in your preferred language

Error creating attributed relationship class

928
2
Jump to solution
07-15-2021 06:45 AM
AlvaroA
Emerging Contributor

Hello everyone,
I have created a code that duplicates feature classes and tables and then duplicates the existing relationships between them.

This is the workflow:
1. duplicate fcl and tables
2. for each fcl or table I copy the information of the relationship
3. than I create the relationships for the duplicate fcl or table using the following code

IFields campiAttributed = null;
if (relationshipEsistente.IsAttributed)
{
try
{
ITable table = (AttributedRelationshipClass)relationshipEsistente as ITable;
campiAttributed = table.Fields;
}
catch (Exception ee)
{ }
}
try
{
IRelationshipClass relClass = featureWorkspace.CreateRelationshipClass
(nomeRelazione, (IObjectClass)featureWorkspace.OpenTable(nome + "__" + nomeTabellaOrig),
(IObjectClass)featureWorkspace.OpenTable(nome + "__" + nomeTabellaDest), relationshipEsistente.ForwardPathLabel, relationshipEsistente.BackwardPathLabel,
relationshipEsistente.Cardinality, relationshipEsistente.Notification, relationshipEsistente.IsComposite, relationshipEsistente.IsAttributed, campiAttributed,
relationshipEsistente.OriginPrimaryKey, relationshipEsistente.DestinationPrimaryKey, relationshipEsistente.OriginForeignKey, relationshipEsistente.DestinationForeignKey);
}

The problem is this, the 1:1 and 1:N relationship are replicated correctly, the attributed relationship N:M with additional attributes is created correctly but is empty. I found out this problem because I can't navigate between objects in the fcl and table, than I inspected the relationship with the tool Make Query Table (Data Management) and it is empty.

Should I use an alternative way?

Thank you.

0 Kudos
1 Solution

Accepted Solutions
nicogis
MVP Frequent Contributor

Hi, AlvaroA 

The Fields object passed to the relAttrFields parameter should not be an object retrieved from another class. If the new class is going to have the same fields as an existing class, cast the existing class' fields collection to the IClone interface, clone it, and use the cloned fields collection as input for this method.

Can be help you ?

View solution in original post

2 Replies
nicogis
MVP Frequent Contributor

Hi, AlvaroA 

The Fields object passed to the relAttrFields parameter should not be an object retrieved from another class. If the new class is going to have the same fields as an existing class, cast the existing class' fields collection to the IClone interface, clone it, and use the cloned fields collection as input for this method.

Can be help you ?

AlvaroA
Emerging Contributor

I used:

IClone cloneFields = table.Fields as IClone;
campiAttributed = cloneFields.Clone() as IFields;

And it works more efficently.

Than I filled the new relationship with as a copy of the existing one (manually) and now all works well.

 

0 Kudos