Share via


Tables 属性

获取或设置表示作用域中的表的 DbSyncTableDescription 对象的列表。

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

语法

声明
Public ReadOnly Property Tables As DbSyncTableDescriptionCollection
    Get
用法
Dim instance As DbSyncScopeDescription
Dim value As DbSyncTableDescriptionCollection

value = instance.Tables
public DbSyncTableDescriptionCollection Tables { get; }
public:
property DbSyncTableDescriptionCollection^ Tables {
    DbSyncTableDescriptionCollection^ get ();
}
member Tables : DbSyncTableDescriptionCollection
function get Tables () : DbSyncTableDescriptionCollection

属性值

类型:Microsoft.Synchronization.Data. . :: . .DbSyncTableDescriptionCollection
表示作用域中的表的 DbSyncTableDescription 对象的列表。

示例

下面的代码示例描述一个名为 filtered_customer 的作用域,并且将三个表添加到该作用域:Customer、CustomerContact 和 NewTable。前两个表已存在于服务器数据库中,因此,使用 GetDescriptionForTable 方法从服务器数据库中检索架构。将包括来自 Customer 表的所有列,但只包括来自 CustomerContact 表的两列。NewTable 表通过使用 DbSyncTableDescriptionDbSyncColumnDescription 对象进行定义,然后在服务器数据库(以及与其同步的其他数据库)中创建该表。若要在完整示例上下文中查看此代码,请参见如何配置和执行数据库同步 (SQL Server)

DbSyncScopeDescription scopeDesc = new DbSyncScopeDescription("filtered_customer");

// Definition for Customer.
DbSyncTableDescription customerDescription =
    SqlSyncDescriptionBuilder.GetDescriptionForTable("Sales.Customer", serverConn);
scopeDesc.Tables.Add(customerDescription);


// Definition for CustomerContact, including the list of columns to include.
Collection<string> columnsToInclude = new Collection<string>();
columnsToInclude.Add("CustomerId");
columnsToInclude.Add("PhoneType");
DbSyncTableDescription customerContactDescription =
    SqlSyncDescriptionBuilder.GetDescriptionForTable("Sales.CustomerContact", columnsToInclude, serverConn);

scopeDesc.Tables.Add(customerContactDescription);

DbSyncTableDescription newTableDescription = new DbSyncTableDescription("Sales.NewTable");

DbSyncColumnDescription newTableIdCol = new DbSyncColumnDescription();
DbSyncColumnDescription newTableContentCol = new DbSyncColumnDescription();

newTableIdCol.UnquotedName = "NewTableId";
newTableIdCol.Type = "int";
newTableIdCol.IsPrimaryKey = true;

newTableContentCol.UnquotedName = "NewTableContent";
newTableContentCol.Type = "nvarchar";
newTableContentCol.Size = "100";
newTableContentCol.IsPrimaryKey = false;

newTableDescription.Columns.Add(newTableIdCol);
newTableDescription.Columns.Add(newTableContentCol);
scopeDesc.Tables.Add(newTableDescription);
Dim scopeDesc As New DbSyncScopeDescription("filtered_customer")

' Definition for Customer. 
Dim customerDescription As DbSyncTableDescription = SqlSyncDescriptionBuilder.GetDescriptionForTable("Sales.Customer", serverConn)
scopeDesc.Tables.Add(customerDescription) 


' Definition for CustomerContact, including the list of columns to include. 
Dim columnsToInclude As New Collection(Of String)()
columnsToInclude.Add("CustomerId") 
columnsToInclude.Add("PhoneType") 
Dim customerContactDescription As DbSyncTableDescription = SqlSyncDescriptionBuilder.GetDescriptionForTable("Sales.CustomerContact", columnsToInclude, serverConn)

scopeDesc.Tables.Add(customerContactDescription) 

Dim newTableDescription As New DbSyncTableDescription("Sales.NewTable")

Dim newTableIdCol As New DbSyncColumnDescription()
Dim newTableContentCol As New DbSyncColumnDescription()

newTableIdCol.UnquotedName = "NewTableId" 
newTableIdCol.Type = "int" 
newTableIdCol.IsPrimaryKey = True 

newTableContentCol.UnquotedName = "NewTableContent" 
newTableContentCol.Type = "nvarchar" 
newTableContentCol.Size = "100" 
newTableContentCol.IsPrimaryKey = False 

newTableDescription.Columns.Add(newTableIdCol) 
newTableDescription.Columns.Add(newTableContentCol) 
scopeDesc.Tables.Add(newTableDescription) 

请参阅

参考

DbSyncScopeDescription类

DbSyncScopeDescription 成员

Microsoft.Synchronization.Data 命名空间