Freigeben über


FilterClause-Eigenschaft

Gibt die SQL WHERE-Klausel an (ohne das Schlüsselwort WHERE), die zum Filtern des Resultsets aus der Basistabelle verwendet wird, oder legt sie fest.

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

Syntax

'Declaration
Public Property FilterClause As String
    Get
    Set
'Usage
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)

Eigenschaftenwert

Typ: System. . :: . .String
Die SQL WHERE-Klausel (ohne das Schlüsselwort WHERE), die zum Filtern des Resultsets aus der Basistabelle verwendet wird.

Hinweise

Die Filterklausel ist eine WHERE-Klausel ohne das WHERE-Schlüsselwort. Sie enthält einen Alias von [side] für die Sync Framework-Änderungsnachverfolgungstabelle. Wenn Sie zum Beispiel eine Tabelle filtern möchten, sodass nur Kunden aus Kalifornien zurückgegeben werden, sähe die Filterklausel etwa wie folgt aus: [side].[SalesTerritory] = 'CA'. Geben Sie die Spalten, die in dieser Filterklausel enthalten sind, mithilfe von AddFilterColumn an.

Die Filterklausel kann ebenso Parameter für die parameterbasierte Filterung enthalten. Zur Filterung basierend auf dem Kundentyp würde die Filterklausel beispielsweise folgendermaßen aussehen: [side].[CustomerType] = @customertype

Die Aliase [base] und [side] werden durch Sync Framework definiert. [base] bezieht sich auf den Basisnamen für die Tabelle, und [side] bezieht sich auf die Tabelle für die Nachverfolgung von Änderungen. Zum Beispiel wird die Customer-Tabelle auf Grundlage der CustomerType-Spalte gefiltert. Standardmäßig ist [base] ein Alias für [Customer] und [side] ein Alias für [Customer_tracking]. Da die CustomerType-Spalte sowohl in den Basis- als auch den Nachverfolgungstabellen enthalten ist, müssen Verweise darauf in der Filterklausel qualifiziert werden. Andernfalls ist die Spalte nicht eindeutig, was zu einem Fehler führt. Sie können auch die echten Tabellennamen anstelle der Aliase [base] und [side] verwenden, zum Beispiel [Customer_tracking].[CustomerType] = @customertype.

Beispiele

Im folgenden Beispiel wird gezeigt, wie eine Filtervorlage erstellt wird, die mithilfe eines Parameters basierend auf einer CustomerType-Spalte der Tabelle filtert.

// 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()

Siehe auch

Verweis

SqlSyncTableProvisioning Klasse

SqlSyncTableProvisioning-Member

Microsoft.Synchronization.Data.SqlServer-Namespace

Andere Ressourcen

Vorgehensweise: Filtern von Daten für die Datenbanksynchronisierung (SQL Server)