SyncSchema Class

Represents the schema information that is required to create tables that are involved in synchronization.

Inheritance Hierarchy

System.Object
  Microsoft.Synchronization.Data.SyncSchema

Namespace:  Microsoft.Synchronization.Data
Assembly:  Microsoft.Synchronization.Data (in Microsoft.Synchronization.Data.dll)

Syntax

'Declaration
<SerializableAttribute> _
Public Class SyncSchema _
    Implements IDisposable
'Usage
Dim instance As SyncSchema
[SerializableAttribute]
public class SyncSchema : IDisposable
[SerializableAttribute]
public ref class SyncSchema : IDisposable
[<SerializableAttribute>]
type SyncSchema =  
    class
        interface IDisposable
    end
public class SyncSchema implements IDisposable

The SyncSchema type exposes the following members.

Constructors

  Name Description
Public method SyncSchema() Initializes a new instance of the SyncSchema class by using default values.
Public method SyncSchema(DataSet) Initializes a new instance of the SyncSchema class by using a data set parameter.
Public method SyncSchema(SyncSchema) Initializes a new instance of the SyncSchema class by passing an existing SyncSchema object as a parameter.

Top

Properties

  Name Description
Public property SchemaDataSet Gets or sets a DataSet object that contains schema information for one or more tables.
Public property Tables Gets a SyncSchemaTables collection. This includes the tables that are contained in the SyncSchema.

Top

Methods

  Name Description
Public method Dispose() Releases all resources used by the SyncSchema.
Protected method Dispose(Boolean) Releases the unmanaged resources used by the SyncSchema and optionally releases the managed resources.
Public method Equals (Inherited from Object.)
Protected method Finalize (Inherited from Object.)
Public method GetHashCode (Inherited from Object.)
Public method GetType (Inherited from Object.)
Protected method MemberwiseClone (Inherited from Object.)
Public method Merge Merges an existing SyncSchema object into the current SyncSchema object.
Public method ToString (Inherited from Object.)

Top

Remarks

The SyncSchema object contains the schema information for synchronization. You can manually construct this object so the client can obtain the schema information directly without accessing the underlying database on the server side.

Examples

The following code example creates the schema for the OrderHeader and OrderDetail tables. The code first creates a schema based on a DataSet that contains only the OrderHeader table. As with the SyncAdapter, the table name must match the SyncTable name. The schema for the OrderDetail table is then added manually. This is the place to map data types if the application requires it.

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

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

Microsoft.Synchronization.Data Namespace