Поделиться через


Свойство FilterClause

Возвращает или задает выражение 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
Выражение WHERE (без ключевого слова WHERE) для фильтрации результирующего набора из базовой таблицы.

Замечания

Выражением фильтрации является предложение WHERE без ключевого слова WHERE. Оно включает псевдоним [side] для таблицы отслеживания изменений платформы Sync Framework. Например, если нужно выполнить фильтрацию таблицы, чтобы были возвращены только результаты по заказчикам из Калифорнии, выражение фильтрации будет выглядеть примерно так: [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)