Columns 属性
获取表示表中的列的 DbSyncColumnDescription 对象的列表。
命名空间: Microsoft.Synchronization.Data
程序集: Microsoft.Synchronization.Data(在 Microsoft.Synchronization.Data.dll 中)
语法
声明
Public ReadOnly Property Columns As DbSyncColumnDescriptionCollection
Get
用法
Dim instance As DbSyncTableDescription
Dim value As DbSyncColumnDescriptionCollection
value = instance.Columns
public DbSyncColumnDescriptionCollection Columns { get; }
public:
property DbSyncColumnDescriptionCollection^ Columns {
DbSyncColumnDescriptionCollection^ get ();
}
member Columns : DbSyncColumnDescriptionCollection
function get Columns () : DbSyncColumnDescriptionCollection
属性值
类型:Microsoft.Synchronization.Data. . :: . .DbSyncColumnDescriptionCollection
表示表中的列的 DbSyncColumnDescription 对象的列表。
示例
下面的代码示例描述一个名为 filtered_customer 的作用域,并且将三个表添加到该作用域:Customer、CustomerContact 和 NewTable。前两个表已存在于服务器数据库中,因此,使用 GetDescriptionForTable 方法从服务器数据库中检索架构。将包括来自 Customer 表的所有列,但只包括来自 CustomerContact 表的两列。NewTable 表通过使用 DbSyncTableDescription 和 DbSyncColumnDescription 对象进行定义,然后在服务器数据库(以及与其同步的其他数据库)中创建该表。若要在完整示例上下文中查看此代码,请参见如何配置和执行数据库同步 (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)