次の方法で共有


FilterClause プロパティ

ベース テーブルの結果セットをフィルター処理するために使用される SQL の WHERE 句 (WHERE キーワードなし) を取得または設定します。

名前空間:  Microsoft.Synchronization.Data.SqlServer
アセンブリ:  Microsoft.Synchronization.Data.SqlServer (Microsoft.Synchronization.Data.SqlServer.dll 内)

構文

'宣言
Public Property FilterClause As String
    Get
    Set
'使用
Dim instance As SqlSyncTableProvisioning
Dim value As String

value = instance.FilterClause

instance.FilterClause = value
public string FilterClause { get; set; }
public:
property String^ FilterClause {
    String^ get ();
    void set (String^ value);
}
member FilterClause : string with get, set
function get FilterClause () : String
function set FilterClause (value : String)

プロパティ値

型 : System. . :: . .String
ベース テーブルの結果セットをフィルター処理するために使用される SQL の WHERE 句 (WHERE キーワードなし)。

説明

フィルター句は、WHERE キーワードのない WHERE 句です。フィルター句には、Sync Framework 変更追跡テーブルに対する [side] の別名が含まれています。たとえば、カリフォルニアの顧客のみを結果として返すようにテーブルをフィルター処理する場合、フィルター句は [side].[SalesTerritory] = 'CA' のようになります。このフィルター句に含まれている列を指定するには、AddFilterColumn を使用します。

このフィルター句には、パラメーターベースのフィルター選択のパラメーターを含めることもできます。たとえば、顧客の種類に基づいてフィルター選択する場合、フィルター句は、[side].[CustomerType] = @customertype のようになります。

別名 [base] および [side] は Sync Framework によって定義されます。[base] はテーブルのベース名を指し、[side] は変更追跡テーブルを指します。たとえば、Customer テーブルは CustomerType 列に基づいてフィルター選択されます。既定では、[base] は [Customer] の別名であり、[side] は [Customer_tracking] の別名です。CustomerType 列は、ベース テーブルと追跡テーブルの両方にあるので、フィルター句でこの列を参照する場合は修飾する必要があります。そうしない場合、どちらの列かがあいまいなため、エラーになります。[base] および [side] という別名の代わりに、実際のテーブル名を使用して、[Customer_tracking].[CustomerType] = @customertype のようにすることもできます。

次の例では、パラメーターを使用してテーブルの CustomerType 列に基づいてフィルター選択するフィルター テンプレートを作成する方法を示します。

// Create a scope named "customertype_template", and add two tables to the scope.
// GetDescriptionForTable gets the schema of each table, so that tracking 
// tables and triggers can be created for that table.
DbSyncScopeDescription scopeDesc = new DbSyncScopeDescription("customertype_template");

// Set a friendly description of the template.
scopeDesc.UserDescription = "Template for Customer and CustomerContact tables. Customer data is filtered by CustomerType parameter.";

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

// Create a provisioning object for "customertype_template" that can be used to create a template
// from which filtered synchronization scopes can be created. We specify that
// all synchronization-related objects should be created in a 
// database schema named "Sync". If you specify a schema, it must already exist
// in the database.
SqlSyncScopeProvisioning serverTemplate = new SqlSyncScopeProvisioning(serverConn, scopeDesc, SqlSyncScopeProvisioningType.Template);
serverTemplate.ObjectSchema = "Sync";

// Specify the column in the Customer table to use for filtering data, 
// and the filtering clause to use against the tracking table.
// "[side]" is an alias for the tracking table.
// The CustomerType column that defines the filter is set up as a parameter in this template.
// An actual customer type will be specified when the synchronization scope is created.
serverTemplate.Tables["Sales.Customer"].AddFilterColumn("CustomerType");
serverTemplate.Tables["Sales.Customer"].FilterClause = "[side].[CustomerType] = @customertype";
SqlParameter param = new SqlParameter("@customertype", SqlDbType.NVarChar, 100);
serverTemplate.Tables["Sales.Customer"].FilterParameters.Add(param);

// Create the "customertype_template" template in the database.
// This action creates tables and stored procedures in the database, so appropriate database permissions are needed.
serverTemplate.Apply();
' Create a scope named "customertype_template", and add two tables to the scope.
' GetDescriptionForTable gets the schema of each table, so that tracking 
' tables and triggers can be created for that table.
Dim scopeDesc As New DbSyncScopeDescription("customertype_template")

' Set a friendly description of the template.
scopeDesc.UserDescription = "Template for Customer and CustomerContact tables. Customer data is filtered by CustomerType parameter."

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

' Create a provisioning object for "customertype_template" that can be used to create a template
' from which filtered synchronization scopes can be created. We specify that
' all synchronization-related objects should be created in a 
' database schema named "Sync". If you specify a schema, it must already exist
' in the database.
Dim serverTemplate As New SqlSyncScopeProvisioning(serverConn, scopeDesc, SqlSyncScopeProvisioningType.Template)
serverTemplate.ObjectSchema = "Sync"

' Specify the column in the Customer table to use for filtering data, 
' and the filtering clause to use against the tracking table.
' "[side]" is an alias for the tracking table.
' The CustomerType column that defines the filter is set up as a parameter in this template.
' An actual customer type will be specified when the synchronization scope is created.
serverTemplate.Tables("Sales.Customer").AddFilterColumn("CustomerType")
serverTemplate.Tables("Sales.Customer").FilterClause = "[side].[CustomerType] = @customertype"
Dim param As New SqlParameter("@customertype", SqlDbType.NVarChar, 100)
serverTemplate.Tables("Sales.Customer").FilterParameters.Add(param)

' Create the "customertype_template" template in the database.
' This action creates tables and stored procedures in the database, so appropriate permissions are needed.
serverTemplate.Apply()

参照

参照

SqlSyncTableProvisioningクラス

SqlSyncTableProvisioning メンバー

Microsoft.Synchronization.Data.SqlServer 名前空間

その他の技術情報

方法: データベース同期用にデータをフィルター選択する (SQL Server)