Load xClass and xProperties, and link xProperties to multiple xClasses from AML

We want to load 1k+ xclasses to Aras, we are talking about 4k+ xproperties here.

 

When we are running AML for creating relations xClass_xProperty_Flatten and xClass_xPropertyDefinition to link them to class tree, it fails with error :

<faultstring><![CDATA["xClass_xProperty_Flatten" can be added or deleted or updated only in XTree context]]></faultstring>

<detail>

        <af:legacy_detail><![CDATA["xClass_xProperty_Flatten" can be added or deleted or updated only in XTree context]]></af:legacy_detail>

        <af:exception message="&quot;xClass_xProperty_Flatten&quot; can be added or deleted or updated only in XTree context" type="System.ArgumentException" />

      </detail>

 

I can load property definitions, but not classes, but can’t map the properties to classes. How can we mass create and reuse these xProperty definitions in more than one class from AML, by creating relations correctly?