Answered by:
Creating foreign keys

Question
-
Hi,
When there is no database (sqlCe) on the client I create it by intializing a synchronize. Unfortunately the foreign keys are not created.
In the server method GetSchema I try this:
syncSchema.Tables["product"].ForeignKeys.Add("product_manufacturer", "manufacturer", "manufacturerid", "product", "manufacturerid");
But it doens't work. Is there documentation for this? I found some other threads where AddRelation to the SchemaDataSet is mentioned but that doesn't work because of the type DataColumn and SyncColumn...
Thank you- Moved by Hengzhe Li Friday, April 22, 2011 3:20 AM (From:SyncFx - Microsoft Sync Framework Database Providers [ReadOnly])
Monday, May 4, 2009 7:33 PM
Answers
-
Hello,
I add the foreign keys on the server side in the GetSchema method to the SyncSchema.Tables[n].ForeignKeys collection. When handling the CreatingSchema event of the DataCacheClientProvider (local database sync provider) all the foreign keys are present in the SyncSchema.Tables[n].ForeignKeys collection, but they are not created in the database...
Could it be the order in which the tables are created? Eg. the foreign key creation fails because the foreign- or primarytable is not created yet, or are all the tables created at once?
Thank you
Edit: The problem was indeed the sequence of the tables in the sync object...Tuesday, May 5, 2009 7:53 AM
All replies
-
Hi,
You can add foreign keys modifying the SyncSchema in the following manner.
SyncSchema.Tables[tableName].ForeignKeys.Add(fk_name, parent_table, parent_column, child_table, child_column)
The SyncSchema object should be available in the Creating Schema event on the "Microsoft.Synchronization.Data.SqlServerCe.SqlCeClientSyncProvider" object.
thanks
Sudarshan
Development Lead , MicrosoftMonday, May 4, 2009 11:11 PMModerator -
Hello,
I add the foreign keys on the server side in the GetSchema method to the SyncSchema.Tables[n].ForeignKeys collection. When handling the CreatingSchema event of the DataCacheClientProvider (local database sync provider) all the foreign keys are present in the SyncSchema.Tables[n].ForeignKeys collection, but they are not created in the database...
Could it be the order in which the tables are created? Eg. the foreign key creation fails because the foreign- or primarytable is not created yet, or are all the tables created at once?
Thank you
Edit: The problem was indeed the sequence of the tables in the sync object...Tuesday, May 5, 2009 7:53 AM