Share via


DbSyncAdapter 类

表示一组命令,这些命令用于在本地对等数据库中检索及应用数据和元数据变更。

命名空间:  Microsoft.Synchronization.Data
程序集:  Microsoft.Synchronization.Data(在 Microsoft.Synchronization.Data.dll 中)

语法

声明
Public Class DbSyncAdapter
用法
Dim instance As DbSyncAdapter
public class DbSyncAdapter
public ref class DbSyncAdapter
type DbSyncAdapter =  class end
public class DbSyncAdapter

注释

DbSyncAdapter 在 DbSyncProvider 和对等数据库之间起到桥梁的作用。同步适配器模仿 ADO.NET 中的数据适配器,并为进行同步的每个表定义同步适配器。同步适配器为对等同步提供程序提供了与对等数据库交互所需的特定命令,例如 InsertCommand,此命令可从一个对等数据库向另一个对等数据库应用插入。由于同步适配器使用 ADO.NETDbCommand 对象,因此可以使用 ADO.NET 支持的任意命令结构。这包括内联 Transact-SQL、存储过程、视图、函数等。这些命令只需要定义了要传输和应用的结构和数据的单个结果。

示例

以下代码示例为 Customer 表创建 SyncAdapter 对象,指定应使用 CustomerId 列来标识表中的每一行,并为 SelectIncrementalChangesCommand 属性指定命令。所调用的存储过程在 用于数据库提供程序帮助主题的安装脚本中定义。有关适配器命令的更多信息以及要在完整示例的上下文中查看此代码,请参见如何为协作同步设置服务器数据库(非 SQL Server)

DbSyncAdapter adapterCustomer = new DbSyncAdapter("Customer");


//Specify the primary key, which Sync Framework uses
//to identify each row during synchronization.
adapterCustomer.RowIdColumns.Add("CustomerId");
SqlCommand chgsCustomerCmd = new SqlCommand();
chgsCustomerCmd.CommandType = CommandType.StoredProcedure;
chgsCustomerCmd.CommandText = "Sync.sp_Customer_SelectChanges";
chgsCustomerCmd.Parameters.Add("@" + DbSyncSession.SyncMetadataOnly, SqlDbType.Int);
chgsCustomerCmd.Parameters.Add("@" + DbSyncSession.SyncMinTimestamp, SqlDbType.BigInt);
chgsCustomerCmd.Parameters.Add("@" + DbSyncSession.SyncScopeLocalId, SqlDbType.Int);
chgsCustomerCmd.Parameters.Add("@" + DbSyncSession.SyncInitialize, SqlDbType.Int);

adapterCustomer.SelectIncrementalChangesCommand = chgsCustomerCmd;
Dim adapterCustomer As New DbSyncAdapter("Customer")

'Specify the primary key, which Sync Framework uses
'to identify each row during synchronization.
adapterCustomer.RowIdColumns.Add("CustomerId")
Dim chgsCustomerCmd As New SqlCommand()

With chgsCustomerCmd
    .CommandType = CommandType.StoredProcedure
    .CommandText = "Sync.sp_Customer_SelectChanges"
    .Parameters.Add("@" + DbSyncSession.SyncMetadataOnly, SqlDbType.Int)
    .Parameters.Add("@" + DbSyncSession.SyncMinTimestamp, SqlDbType.BigInt)
    .Parameters.Add("@" + DbSyncSession.SyncScopeLocalId, SqlDbType.Int)
    .Parameters.Add("@" + DbSyncSession.SyncInitialize, SqlDbType.Int)
End With

adapterCustomer.SelectIncrementalChangesCommand = chgsCustomerCmd

继承层次结构

System. . :: . .Object
  Microsoft.Synchronization.Data..::..DbSyncAdapter

线程安全

此类型的所有公共成员static(在 Visual Basic 中为 Shared) 都是线程安全的。不保证所有实例成员都是线程安全的。

请参阅

参考

DbSyncAdapter 成员

Microsoft.Synchronization.Data 命名空间