DbSyncAdapter 类

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

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

语法

声明
<SuppressMessageAttribute("Microsoft.Naming", "CA1706:ShortAcronymsShouldBeUppercase")> _
Public Class DbSyncAdapter
用法
Dim instance As DbSyncAdapter
[SuppressMessageAttribute("Microsoft.Naming", "CA1706:ShortAcronymsShouldBeUppercase")] 
public class DbSyncAdapter
[SuppressMessageAttribute(L"Microsoft.Naming", L"CA1706:ShortAcronymsShouldBeUppercase")] 
public ref class DbSyncAdapter
/** @attribute SuppressMessageAttribute("Microsoft.Naming", "CA1706:ShortAcronymsShouldBeUppercase") */ 
public class DbSyncAdapter
SuppressMessageAttribute("Microsoft.Naming", "CA1706:ShortAcronymsShouldBeUppercase") 
public class DbSyncAdapter

备注

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

示例

以下代码示例为 Customer 表创建 SyncAdapter 对象,指定应使用 CustomerId 列来标识表中的每一行,并为 SelectIncrementalChangesCommand 属性指定命令。所调用的存储过程在 用于 Sync Services 帮助主题的安装脚本中定义。有关适配器命令的更多信息以及要在完整示例的上下文中查看此代码,请参见如何配置变更跟踪和同步对等方

DbSyncAdapter adapterCustomer = new DbSyncAdapter("Customer");


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

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

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

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

adapterCustomer.SelectIncrementalChangesCommand = chgsCustomerCmd

继承层次结构

System.Object
  Microsoft.Synchronization.Data.DbSyncAdapter

线程安全

此类型的所有公共静态(在 Visual Basic 中共享 )成员都是线程安全的。不保证任何实例成员的线程安全。

请参阅

参考

DbSyncAdapter 成员
Microsoft.Synchronization.Data 命名空间