Introduction:
Filters are the fundamental way in which the Business Data Connectivity (BDC)
service captures user input (or system input) and provides it to the back-end
API invocation. Filters describe where a filter value should be inserted in a
complex series of parameters. In this article we will be seeing how to create
Comparison Filter Descriptor to a Finder Method.
Description:
I have a custom list "Customers" which has the following data's.
I have created an external content type based on the above SharePoint custom
list. To create an external content type based on SharePoint list please refer this article. In the above same project I am going to add Comparison Filter Descriptor. I am
going to retrieve specific items based on the "CustomerID" using comparison
filter descriptor.
Comparison Filter Descriptor:
- In the solution, double click on BDCModel.
- In the BDC Method Details window, expand the ReadList node, expand the Parameter node and then add a Parameter.
- In the BDC Method Details window, expand the ReadList node, expand the Parameters node.
- In the Add a Parameter drop down list, click Create Parameter.
- In the BDC explorer, expand the ReadList node and then select the parameter that we have created.
- Right click on parameter, and click on Properties.
- Change the name of the parameter as id as shown in the following.
- Right click on idTypeDescriptor, and then click on Properties.
- Change the Type Name to System.Int32.
- Expand the Filter Descriptors node and then click on Create Filter Descriptor.
- In the View Menu, click on Properties.
- Change the Type to Comparison and Name to ComparisonFilterDescriptor.
- Click on the drop down next to the Associated Type Descriptors.
- Select the idTypeDescriptor.
- In the solution explorer, click on CustomersService.cs and replace ReadList method with the following code.
publicstatic IEnumerable<Customers> ReadList(int id)
{
MPDataContext dc =new MPDataContext(newUri("http:// servername:1111/hr/MP/_vti_bin/listdata.svc"));
dc.Credentials = CredentialCache.DefaultNetworkCredentials;
int NoValuePassed = 0;
int DefaultValue = 100;
if (id == NoValuePassed)
{
id = DefaultValue;
}
var customers =
from ein dc.Customers
where e.CustomerID>id
selectnew Customers()
{
CustomerID = (int)e.CustomerID,
CustomerName = e.CustomerName,
};
return customers;
}
Deploy the solution:
- Right click on the solution and click on Build.
- Deploy the solution.
- Go to Central Administration => Application Management => Manage Service Applications => Business Data Connectivity Services => You could see the content type that we have created as shown in the following.
Testing the solution:
- The solution can be tested by creating an external list based on the external content type that we have created.
- Go to SharePoint Site => Site Actions => More Options.
- Select the external list from the installed templates and click on Create.
- Enter the Name for the list and select the External Content Type that we have created.
- By default all the values are populated because we have mentioned the default value for the filter is 100 in the ReadList method.
- Go to List Settings =>Views.
- Click on ReadList view.
- In the Data Source Filters, change the Filter Value to 102.
- Click on Ok.
- Now only the values which have CustomerID greater than 102 will be populated.