规划步骤 4:确定每个实体所需的筛选器
上次修改时间: 2010年4月19日
适用范围: SharePoint Server 2010
若要确定每个外部内容类型所需的筛选器,请查看每种 Web 方法的所有输入参数并确定希望 Business Data Connectivity (BDC) Service 如何在运行时获取参数的值;例如,在业务数据 Web 部件中等。如果希望用户在运行时指定值,请使用用户筛选器之一。或者,如果希望 BDC 自动提供此值,请使用系统筛选器之一或提供元数据本身中的默认值。
例如,假定在 SampleWebService 代理中使用 GetCustomers 方法。此方法将使用两个输入参数:name 和 limit。如果希望业务数据列表 Web 部件的用户通过提供诸如"Name like 'Jo%'"或"Name contains 'John'"之类的值来筛选 GetCustomers 方法的结果,请将 FilterDescriptor 和 name 输入参数关联。
后端 Web 服务方法应支持您声明的筛选器;否则,此 Web 方法可能不会返回所需结果。首先检查 Web 方法的文档以查看它支持的筛选功能;然后,在元数据中声明 FilterDescriptors。
例如,如果在代理中查看 GetCustomers Web 方法,则会看到此方法采用了两个输入参数(即 name 和 limit),如以下代码中所示。
public Customer[] GetCustomers(string name, [System.Xml.Serialization.XmlElementAttribute(IsNullable=true)] System.Nullable<int> limit) {
object[] results = this.Invoke("GetCustomers", new object[] {
name,
limit});
return ((Customer[])(results[0]));
}
现在,假定此 Web 方法的文档陈述了此方法的用法,如以下代码中所示。
GetCustomers(name, limit) where
name: A string representing the customer's name. This parameter accepts wildcards (that is, '%' representing any string of characters).
limit: A number that limits the number of customers returned in the result set.
这将使您清楚地知道可以将输入参数 name 和 limit 分别与通配符和限制筛选器关联。
当希望为用户显示每个筛选器时(例如,在业务数据 Web 部件中),可以指定这些筛选器。UsedForDisambiguation 属性(FilterDescriptor 的属性)可用于告知外部数据选取器控件和业务数据 Web 部件为筛选器生成匹配候选项列表。Type 属性的值在 FilterDescriptor 的定义中非常重要。此值会告知 BDC 筛选器的种类。它可以是用户筛选器或系统筛选器之一。下面的内容演示 GetCustomers 方法的元数据 XML。
<Method Name="GetCustomers">
<FilterDescriptors>
<FilterDescriptor Type="Wildcard" Name="Name" />
<!-- Limit filter tells Business Data Catalog to bring back
only the specified number of rows back from the line-of-business
application.-->
<!-- Notice that the back-end method should support this
functionality to return only the specified number of rows.
For a sample, see SampleWebService.-->
<FilterDescriptor Type="Limit" Name="Limit" />
</FilterDescriptors>
<Parameters>
<Parameter Direction="In" Name="name">
<TypeDescriptor TypeName="System.String" AssociatedFilter="Name" Name="name" />
</Parameter>
<Parameter Direction="In" Name="limit">
<TypeDescriptor TypeName="System.Int32" AssociatedFilter="Limit" Name="limit" />
</Parameter>
<Parameter Direction="Return" Name="Customers">
<TypeDescriptor TypeName="SampleWebServiceProxy.Customer[], SampleWebService" IsCollection="true" Name="ArrayOfCustomer">
<TypeDescriptors>
<TypeDescriptor TypeName="SampleWebServiceProxy.Customer, SampleWebService" Name="Customer">
<TypeDescriptors>
<TypeDescriptor TypeName="System.String" IdentifierName="CustomerID" Name="CustomerID" />
<TypeDescriptor TypeName="System.String" Name="Name" />
<TypeDescriptor TypeName="System.Int64" Name="WorkPhoneNumber" />
<TypeDescriptor TypeName="System.Int64" Name="MobilePhoneNumber" />
<TypeDescriptor TypeName="System.String" Name="Industry" />
<TypeDescriptor TypeName="System.String" Name="WebSite" />
</TypeDescriptors>
</TypeDescriptor>
</TypeDescriptors>
</TypeDescriptor>
</Parameter>
</Parameters>
<MethodInstances>
<MethodInstance Type="Finder" ReturnParameterName="Customers" ReturnTypeDescriptorName="ArrayOfCustomer" ReturnTypeDescriptorLevel="0" Name="FindCustomerInstances" />
</MethodInstances>
</Method>
有关 BDC 支持的筛选器的列表,请参阅 Business Data Connectivity Service 支持的筛选器的类型。