locked
Foreign Keys not getting created on the client RRS feed

  • Question

  • I'm using Sync Services for ADO.NET (Devices) v1 sp1 to Sync from an Oracle server to a Sql Compact 3.5 client.  I am adding Foreign Key, but they aren't getting created on the client.

                    foreach (XElement xeFK in schemaTables.Descendants("table").First(el => el.Attribute("name").Value == sTable.Name).Element("keys").Descendants("ForeignKey")) 
                    { 
                            String[] fks = xeFK.Value.Split('|'); 
                            ssOracleSchema.Tables[sTable.Name].ForeignKeys.Add(xeFK.Attribute("name").Value, fks[0], fks[1].Split('~'), fks[2], fks[3].Split('~')); 
                    } 
     


    and I've confirmed in debug step-thru that Schema.Tables["tableName"].ForeignKeys actually exist, but after I open the client db in VS2008 >> Table Properties >> Manage Relations - NO Foreign Keys exist.

    Any Ideas?
    • Moved by Hengzhe Li Friday, April 22, 2011 5:51 AM (From:SyncFx - Microsoft Sync Framework Database Providers [ReadOnly])
    Monday, February 2, 2009 9:09 PM

Answers

  • It's a slow moving forum - but answered my own question.  Technically though I would think that ForeignKeys specified in the server schema would be passed on to the client when the schema is created (not true in v1 sp1 though).

    Another post suggested using the SchemaDataSet.Relations - but I couldn't seem to get any of the available constructors to work because a SyncDataColumn cannot be convert to a DataColumn.

    My solution - use the CreatingSchema event and force the ForeignKeys into the client schema (I've got the table schema defined in an external xml file):


    sqlClientSyncProvider.CreatingSchema += new EventHandler<CreatingSchemaEventArgs>(sqlClientSyncProvider_CreatingSchema); 
     
    static void sqlClientSyncProvider_CreatingSchema(object sender, CreatingSchemaEventArgs e) 
        //get the table definitions 
        XElement schemaTables = XElement.Load(@"OracleSchema\TASTableScemas.xml"); 
     
        // Add foreign keys 
        foreach (XElement xeFK in schemaTables.Descendants("table").First(el => el.Attribute("name").Value == e.Table.TableName).Element("keys").Descendants("ForeignKey")) 
        { 
            String[] fks = xeFK.Value.Split('|'); 
            e.Schema.Tables[e.Table.TableName].ForeignKeys.Add(xeFK.Attribute("name").Value, fks[0], fks[1].Split('~'), fks[2], fks[3].Split('~')); 
        } 
    • Marked as answer by viperguynaz Wednesday, February 4, 2009 12:45 AM
    Wednesday, February 4, 2009 12:45 AM