我试图在Sync Framework 2.1的帮助下将Sql Express 2008与Sql Compact 3.5同步
我有2张桌子
我使用以下代码
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();
}
在同步期间,我确实收到过滤后的“客户”表但我还收到完整订单表,当我只想要这些数据的子集时,我的意思是只有属于特定客户的订单。
我尝试过在网上找到的所有选项,例如更改插入顺序,手动添加外键但仍然没有成功。
先谢谢
答案 0 :(得分:0)
我想你已经在这里回答了你的问题:http://social.msdn.microsoft.com/Forums/en-US/syncdevdiscussions/thread/82235748-fac2-435f-8035-8d8809aeb82d
如上所述,Sync Fx单独/独立地同步表。要过滤订单表以仅同步属于同步客户行的行,您还必须过滤订单表:
serverProvision.Tables["Orders"].AddFilterColumn("CustomerId");
serverProvision.Tables["Customers"].FilterClause = string.Format("[side].[CustomerId] in (Select CustomerId from Customers_tracking where CustomerName = '{0}'", userName);