Schema 属性
获取或设置一个 SyncSchema 对象,该对象包含与服务器上的表架构有关的信息。
命名空间: Microsoft.Synchronization.Data.Server
程序集: Microsoft.Synchronization.Data.Server(在 Microsoft.Synchronization.Data.Server.dll 中)
语法
声明
Public Property Schema As SyncSchema
Get
Set
用法
Dim instance As DbServerSyncProvider
Dim value As SyncSchema
value = instance.Schema
instance.Schema = value
public SyncSchema Schema { get; set; }
public:
property SyncSchema^ Schema {
SyncSchema^ get ();
void set (SyncSchema^ value);
}
member Schema : SyncSchema with get, set
function get Schema () : SyncSchema
function set Schema (value : SyncSchema)
属性值
类型:Microsoft.Synchronization.Data. . :: . .SyncSchema
一个 SyncSchema 对象,其中包含有关服务器上表架构的信息。
注释
包含用于同步过程的架构信息的 SyncSchema 对象。您可以手动构造此对象,以使客户端可以直接获取架构信息而无需访问服务器端的基础数据库即。
示例
下面的代码示例创建 OrderHeader 和 OrderDetail 表的架构。代码首先基于一个仅包含 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