I am trying to synchronize Sql Express 2008 with Sql Compact 3.5 with help of Sync Framework 2.1
I have 2 tables
- Customers(PK Id , string Name )
- Orders (PK Id , int Price , s开发者_Go百科tring Name , FK Customer_Id)
I Use the following code
public static void CreateScope(string userName)
{
var serverConn = new SqlConnection(@"Data Source=.\SQLEXPRESS; Initial Catalog=Test; Integrated Security=True");
var scopeDescription = new DbSyncScopeDescription(string.Format("Customer-{0}", userID));
var customersTable = SqlSyncDescriptionBuilder.GetDescriptionForTable("Customers", serverConn);
var ordersTable = SqlSyncDescriptionBuilder.GetDescriptionForTable("Orders", serverConn);
ordersTable.Constraints.Add("FK_Customer_Id", "Customers", "Orders", "Id", "Customer_Id");
scopeDesc.Tables.Add(azmanotTable);
scopeDesc.Tables.Add(customersTable);
var serverProvision = new SqlSyncScopeProvisioning(serverConn, scopeDesc);
serverProvision.SetCreateTableDefault(DbSyncCreationOption.Skip);
serverProvision.Tables["Customers"].AddFilterColumn("CustumerName");
serverProvision.Tables["Customers"].FilterClause = string.Format("[side].[CustumerName] = '{0}'", userName);
serverProvision.Apply();
}
During the Sync I do receive filtered "Customers" table but i also receive full orders table when i wanted only subset of this data , I mean only orders that belong to specific customer.
I have tried all the options i found in web for example to change insert order adding foreign key manually but still no success.
Thanks in Advance
i think you have your question answered here already: http://social.msdn.microsoft.com/Forums/en-US/syncdevdiscussions/thread/82235748-fac2-435f-8035-8d8809aeb82d
as mentioned, Sync Fx synchronizes tables individually/independently. To filter the orders table to synchronize only rows belonging to the synchronized customer rows, you have to filter the orders table as well :
serverProvision.Tables["Orders"].AddFilterColumn("CustomerId");
serverProvision.Tables["Customers"].FilterClause = string.Format("[side].[CustomerId] in (Select CustomerId from Customers_tracking where CustomerName = '{0}'", userName);
精彩评论