title: Sync Framework - The definition of referring columns in referential relationships must match the referred columns
body: <p>I am using Sync Framework. I have two tables Organizers and Events in SQL Server as below:</p>
  
  <pre><code>CREATE TABLE Organizers
  (   
      Id int NOT NULL,
      ClientId UNIQUEIDENTIFIER NOT NULL,
      Name nvarchar(400) NOT NULL,
      [Address] nvarchar(1000) NOT NULL,
      PhoneNo nvarchar(50) NOT NULL,
      PRIMARY KEY (ClientId, Id)
  )
  
  CREATE TABLE [Events]
  (
      Id int NOT NULL,
      ClientId UNIQUEIDENTIFIER NOT NULL,
      OrganizerId int NOT NULL,
      OrganizerClientId UNIQUEIDENTIFIER NOT NULL,
      Name nvarchar(400) NOT NULL,
      Location nvarchar(400) NOT NULL,
      CONSTRAINT fk_Organizers_Events FOREIGN KEY (OrganizerClientId, OrganizerId) REFERENCES Organizers (ClientId, Id),
      PRIMARY KEY (ClientId, Id)
  )
  </code></pre>
  
  <p>To provision the client, I am running the following code:</p>
  
  <pre><code>SqlCeConnection clientCon = new SqlCeConnection(clientConnectionString);
  SqlConnection serverCon = new SqlConnection(serverConnectionString);
  
  var tOrganizers = SqlSyncDescriptionBuilder.GetDescriptionForTable("Organizers", serverCon);
  var tEvents = SqlSyncDescriptionBuilder.GetDescriptionForTable("Events", serverCon);
  
  var pkColumnsOrganizers = new Collection&lt;string&gt; { "Id", "ClientId"};
  var fkColumnsEvents = new Collection&lt;string&gt; { "OrganizerId", "OrganizerClientId"};
  
  var fkEvents = new DbSyncForeignKeyConstraint("FK_Organizers_Events", "Organizers", "Events", pkColumnsOrganizers, fkColumnsEvents);
  tEvents.Constraints.Add(fkEvents);
  
  var scopeDesc = new DbSyncScopeDescription(ScopeName);
  scopeDesc.Tables.Add(tOrganizers);
  scopeDesc.Tables.Add(tEvents);
  
  SqlCeSyncScopeProvisioning clientProvision = new SqlCeSyncScopeProvisioning(clientCon, scopeDesc);
  
  
  if (!clientProvision.ScopeExists(ScopeName))
  {
           clientProvision.Apply();
  }
  </code></pre>
  
  <p>On running the above code, I am getting <code>SqlCeExpception</code> with message: The definition of referring columns (such as number of columns or data types) in referential relationships must match the referred columns. [  Constraint name (if known) = FK_Organizers_Events ]</p>
  
  <p>Is there something wrong in the code ?</p>
  
  <p><strong>Addition:</strong>
  PKs are correctly getting picked by <code>SqlSyncDescriptionBuilder.GetDescriptionForTable("Organizers", serverCon)</code>. Same for Events table as well.</p>
  
  <p><img src="https://i.stack.imgur.com/ldlDj.png" alt="tOrganizers - Quick Watch"></p>