BillForney.com

A day in the life of a geek...

Quick Note: How To Filter Which Tables You Sync

I’m messing with sync framework and am just posting this as a quick note to self, but it might help others too. When syncing with a custom scope I’m using this code to filter on a column.

   1:  var sqlAzureProvisioning = new SqlSyncScopeProvisioning(sqlAzureConnection, scope);
   2:  if (!sqlAzureProvisioning.ScopeExists(FilteredScopeName))
   3:  {
   4:      sqlAzureProvisioning.SetCreateTableDefault(DbSyncCreationOption.CreateOrUseExisting);
   5:      sqlAzureProvisioning.SetCreateTrackingTableDefault(DbSyncCreationOption.CreateOrUseExisting);
   6:      sqlAzureProvisioning.SetCreateTriggersDefault(DbSyncCreationOption.CreateOrUseExisting);
   7:      sqlAzureProvisioning.SetCreateProceduresDefault(DbSyncCreationOption.CreateOrUseExisting);
   8:      sqlAzureProvisioning.SetCreateProceduresForAdditionalScopeDefault(DbSyncCreationOption.CreateOrUseExisting);
   9:      sqlAzureProvisioning.ObjectSchema = "Sync";
  10:   
  11:      sqlAzureProvisioning.Tables["Contacts"].AddFilterColumn("OwnerContactId");
  12:      sqlAzureProvisioning.Tables["Contacts"].FilterClause =
  13:          string.Format("[side].[OwnerContactId] = '{0}'", Properties.Settings.Default.UserContactId);
  14:   
  15:      sqlAzureProvisioning.Apply();
  16:  }

Technorati Tags: ,