Share via


SyncSchema 类

表示创建同步过程涉及的表所需的架构信息。

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

语法

声明
<SerializableAttribute> _
Public Class SyncSchema
    Implements IDisposable
用法
Dim instance As SyncSchema
[SerializableAttribute] 
public class SyncSchema : IDisposable
[SerializableAttribute] 
public ref class SyncSchema : IDisposable
/** @attribute SerializableAttribute() */ 
public class SyncSchema implements IDisposable
SerializableAttribute 
public class SyncSchema implements IDisposable

备注

包含用于同步过程的架构信息的 SyncSchema 对象。您可以手动构造此对象,以使客户端可以直接获取架构信息而无需访问服务器端的基础数据库即。

示例

下面的代码示例创建 OrderHeaderOrderDetail 表的架构。代码首先基于一个仅包含 OrderHeader 表的 DataSet 创建一个架构。和 SyncAdapter 一样,表名必须与 SyncTable 名称匹配。然后手动添加 OrderDetail 表的架构。如果应用程序需要,会在此位置映射数据类型。

DataSet orderHeaderDataSet = Utility.CreateDataSetFromServer();
orderHeaderDataSet.Tables[0].TableName = "OrderHeader";
this.Schema = new SyncSchema(orderHeaderDataSet);

this.Schema.Tables.Add("OrderDetail");

this.Schema.Tables["OrderDetail"].Columns.Add("OrderDetailId");
this.Schema.Tables["OrderDetail"].Columns["OrderDetailId"].ProviderDataType = "int";
this.Schema.Tables["OrderDetail"].Columns["OrderDetailId"].AllowNull = false;

this.Schema.Tables["OrderDetail"].Columns.Add("OrderId");
this.Schema.Tables["OrderDetail"].Columns["OrderId"].ProviderDataType = "uniqueidentifier";
this.Schema.Tables["OrderDetail"].Columns["OrderId"].RowGuid = true;
this.Schema.Tables["OrderDetail"].Columns["OrderId"].AllowNull = false;

this.Schema.Tables["OrderDetail"].Columns.Add("Product");
this.Schema.Tables["OrderDetail"].Columns["Product"].ProviderDataType = "nvarchar";
this.Schema.Tables["OrderDetail"].Columns["Product"].MaxLength = 100;
this.Schema.Tables["OrderDetail"].Columns["Product"].AllowNull = false;

this.Schema.Tables["OrderDetail"].Columns.Add("Quantity");
this.Schema.Tables["OrderDetail"].Columns["Quantity"].ProviderDataType = "int";
this.Schema.Tables["OrderDetail"].Columns["Quantity"].AllowNull = false;
           
//The primary key columns are passed as a string array.
string[] orderDetailPrimaryKey = new string[2];
orderDetailPrimaryKey[0] = "OrderDetailId";
orderDetailPrimaryKey[1] = "OrderId";
this.Schema.Tables["OrderDetail"].PrimaryKey = orderDetailPrimaryKey;
Dim orderHeaderDataSet As DataSet = Utility.CreateDataSetFromServer()
orderHeaderDataSet.Tables(0).TableName = "OrderHeader"
Me.Schema = New SyncSchema(orderHeaderDataSet)

With Me.Schema
    .Tables.Add("OrderDetail")

    .Tables("OrderDetail").Columns.Add("OrderDetailId")
    .Tables("OrderDetail").Columns("OrderDetailId").ProviderDataType = "int"
    .Tables("OrderDetail").Columns("OrderDetailId").AllowNull = False

    .Tables("OrderDetail").Columns.Add("OrderId")
    .Tables("OrderDetail").Columns("OrderId").ProviderDataType = "uniqueidentifier"
    .Tables("OrderDetail").Columns("OrderId").RowGuid = True
    .Tables("OrderDetail").Columns("OrderId").AllowNull = False

    .Tables("OrderDetail").Columns.Add("Product")
    .Tables("OrderDetail").Columns("Product").ProviderDataType = "nvarchar"
    .Tables("OrderDetail").Columns("Product").MaxLength = 100
    .Tables("OrderDetail").Columns("Product").AllowNull = False

    .Tables("OrderDetail").Columns.Add("Quantity")
    .Tables("OrderDetail").Columns("Quantity").ProviderDataType = "int"
    .Tables("OrderDetail").Columns("Quantity").AllowNull = False
End With        

'The primary key columns are passed as a string array.
Dim orderDetailPrimaryKey(1) As String
orderDetailPrimaryKey(0) = "OrderDetailId"
orderDetailPrimaryKey(1) = "OrderId"
Me.Schema.Tables("OrderDetail").PrimaryKey = orderDetailPrimaryKey

继承层次结构

System.Object
  Microsoft.Synchronization.Data.SyncSchema

线程安全

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

请参阅

参考

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