0
Please see my post in Yammer. I uploaded a sample there.
https://www.yammer.com/dynamicsaxfeedbackprograms/#/Threads/show?threadId=79299511926784

For updating the AX7 retail channel schema with tables we introduce in our extensions, we found that we are not able to add table dependencies using the current CDX seed data extension points. We found that since replication happens in alphabetical order some of our tables have data pushed before the tables that it had foreign key references to, which caused an error.

For example, I have tables dbo.TableA, ext.TableA, dbo.TableB, and ext.TableB. ext.TableA has a foreign key constraint to a field in ext.TableB. When replication happens, it appears that it tries to replicate to ext.TableA before ext.TableB, resulting in a foreign key constraint error.

This is a sample create script for the ext tables:
```
use AxDB

CREATE TABLE [ext].[TableA] (
[RECID] [bigint] NOT NULL,
[TableBRecID] [bigint] NOT NULL,
CONSTRAINT [PK_ext.TableA] PRIMARY KEY ([RECID])
)

GRANT SELECT ON OBJECT::ext.TableA TO [DataSyncUsersRole]
GRANT INSERT ON OBJECT::ext.TableA TO [DataSyncUsersRole]
GRANT UPDATE ON OBJECT::ext.TableA TO [DataSyncUsersRole]
GRANT DELETE ON OBJECT::ext.TableA TO [DataSyncUsersRole]

CREATE TABLE [ext].[TableB] (
[RECID] [bigint] NOT NULL,
CONSTRAINT [PK_ext.TableB] PRIMARY KEY ([RECID])
)

GRANT SELECT ON OBJECT::ext.TableB TO [DataSyncUsersRole]
GRANT INSERT ON OBJECT::ext.TableB TO [DataSyncUsersRole]
GRANT UPDATE ON OBJECT::ext.TableB TO [DataSyncUsersRole]
GRANT DELETE ON OBJECT::ext.TableB TO [DataSyncUsersRole]

ALTER TABLE [ext].[TableA] ADD CONSTRAINT [FK_ext.TableA_ext.TableB_TableBRECID] FOREIGN KEY ([TableBRecId]) REFERENCES [ext].[TableB] ([RECID]) ON DELETE CASCADE
```

Our current solution is an event handler we added to the initialize retail scheduler ok button, which triggers code that inserts our tables into the AX7 schema. We'd like to keep the foreign key constraints for data integrity (again, see my yammer post).

Error message:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. --->
Microsoft.Dynamics.Retail.CommerceDataExchange.ProcessDataPackageException: Error occurred when running SqlTargetRequestHandler. --->
Microsoft.Dynamics.Retail.CommerceDataExchange.SqlMergeRequestRunException:

Failed to merge data into table [EXT].[TABLEA]. Query: DELETE FROM [EXT].[TABLEA];MERGE [EXT].[TABLEA] AS dst
USING (SELECT [RECID],[TABLEBRECID] FROM [#EXT_TABLEA_59e33b4a-9995-4239-a32f-0a6314754d94]) AS src
ON (dst.[RECID]=src.[RECID])WHEN MATCHED THEN UPDATE SET [TABLEBRECID]=src.[TABLEBRECID]
WHEN NOT MATCHED THEN INSERT ([RECID],[TABLEBRECID]) VALUES (src.[RECID],src.[TABLEBRECID]);DROP TABLE [#EXT_TABLEA_59e33b4a-9995-4239-a32f-0a6314754d94]; --->

Microsoft.Dynamics.Retail.CommerceDataExchange.SqlWriteRequestRunException:

Failed to run SqlWriteRequestRunner for table [EXT].[TABLEA]. Query: DELETE FROM [EXT].[TABLEA];MERGE [EXT].[TABLEA] AS dst
USING (SELECT [RECID],[TABLEBRECID] FROM [#EXT_TABLEA_59e33b4a-9995-4239-a32f-0a6314754d94]) AS src
ON (dst.[RECID]=src.[RECID])WHEN MATCHED THEN UPDATE SET [TABLEBRECID]=src.[TABLEBRECID]WHEN NOT MATCHED THEN
INSERT ([RECID],[TABLEBRECID]) VALUES (src.[RECID],src.[TABLEBRECID]);DROP TABLE [#EXT_TABLEA_59e33b4a-9995-4239-a32f-0a6314754d94]; --->

Microsoft.Dynamics.Retail.CommerceDataExchange.PerformWriteOperationException: Error when writing data to table [EXT].[TABLEA]. Query:

DELETE FROM [EXT].[TABLEA];MERGE [EXT].[TABLEA] AS dst
USING (SELECT [RECID],[TABLEBRECID] FROM [#EXT_TABLEA_59e33b4a-9995-4239-a32f-0a6314754d94]) AS src
ON (dst.[RECID]=src.[RECID])WHEN MATCHED THEN
UPDATE SET [TABLEBRECID]=src.[TABLEBRECID]WHEN NOT MATCHED THEN INSERT ([RECID],[TABLEBRECID])
VALUES (src.[RECID],src.[TABLEBRECID]);DROP TABLE [#EXT_TABLEA_59e33b4a-9995-4239-a32f-0a6314754d94]; --->

System.Data.SqlClient.SqlException: The MERGE statement conflicted with the FOREIGN KEY constraint "FK_ext.TableA_ext.TableB_TableBRECID". The conflict occurred in
database "AxDB", table "ext.TableB", column 'RECID'.The statement has been terminated.

at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at Microsoft.Dynamics.Retail.CommerceDataExchange.SqlWriteRequestRunner.PerformWriteOperation(SqlConnection connection)
--- End of inner exception stack trace ---
at Microsoft.Dynamics.Retail.CommerceDataExchange.SqlWriteRequestRunner.PerformWriteOperation(SqlConnection connection)
at Microsoft.Dynamics.Retail.CommerceDataExchange.SqlWriteRequestRunner.Run(SqlConnection connection)
--- End of inner exception stack trace ---
at Microsoft.Dynamics.Retail.CommerceDataExchange.SqlWriteRequestRunner.Run(SqlConnection connection)
at Microsoft.Dynamics.Retail.CommerceDataExchange.SqlMergeRequestRunner.Run(SqlConnection connection)
--- End of inner exception stack trace ---
at Microsoft.Dynamics.Retail.CommerceDataExchange.SqlMergeRequestRunner.Run(SqlConnection connection)
at Microsoft.Dynamics.Retail.CommerceDataExchange.SqlTargetRequestHandler.ProcessWriteRequest(SqlConnection connection)
at Microsoft.Dynamics.Retail.CommerceDataExchan

Repro steps:
1. Create dbo.TableA, dbo.TableB in a back office project.
1. Add a int64 field to dbo.TableA named TableBRecId.
1. Add a foreign key relation to dbo.TableA that relates dbo.TableA.TableBRecId to dbo.TableB.RecId
2. Run create script in other text box to create ext.TableA and ext.TableB.
3. Add code necessary to replicate dbo.TableA to ext.TableA and dbo.TableB to ext.TableB.
4. Go into SQL management studio and manually add a row to dbo.TableA and dbo.TableB.
5. Run the replication job.
STATUS DETAILS
Declined
Ideas Administrator

Thank you for sharing your idea with us. We appreciate and value your input. While we have decided not to pursue it at this time, we will keep it on our radar and re-evaluate it in the future if there is increased demand from our customers.