How to add a Comparison Filter Descriptor to a Finder Method in Business Data Connectivity Model

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.

filfindmetd1.gif


filfindmetd2.gif

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:

  1. In the solution, double click on BDCModel.

    filfindmetd3.gif
     
  2. In the BDC Method Details window, expand the ReadList node, expand the Parameter node and then add a Parameter.

    filfindmetd4.gif
     
  3. In the BDC Method Details window, expand the ReadList node, expand the Parameters node.
  4. In the Add a Parameter drop down list, click Create Parameter.
  5. In the BDC explorer, expand the ReadList node and then select the parameter that we have created.

    filfindmetd5.gif
     
  6. Right click on parameter, and click on Properties.
  7. Change the name of the parameter as id as shown in the following.

    filfindmetd6.gif
     
  8. Right click on idTypeDescriptor, and then click on Properties.

    filfindmetd7.gif
     
  9. Change the Type Name to System.Int32.

    filfindmetd8.gif
     
  10. Expand the Filter Descriptors node and then click on Create Filter Descriptor.

    filfindmetd9.gif

  11. In the View Menu, click on Properties.
  12. Change the Type to Comparison and Name to ComparisonFilterDescriptor.

    filfindmetd10.gif
     
  13. Click on the drop down next to the Associated Type Descriptors.
  14. Select the idTypeDescriptor.

    filfindmetd11.gif
     
  15. 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:

  1. Right click on the solution and click on Build.
  2. Deploy the solution.
  3. 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.

    filfindmetd12.gif

Testing the solution:

  1. The solution can be tested by creating an external list based on the external content type that we have created.
  2. Go to SharePoint Site => Site Actions => More Options.
  3. Select the external list from the installed templates and click on Create.

    filfindmetd13.gif
     
  4. Enter the Name for the list and select the External Content Type that we have created.

    filfindmetd14.gif
     
  5. By default all the values are populated because we have mentioned the default value for the filter is 100 in the ReadList method.

    filfindmetd15.gif
     
  6. Go to List Settings =>Views.

    filfindmetd16.gif
     
  7. Click on ReadList view.
  8. In the Data Source Filters, change the Filter Value to 102.

    filfindmetd17.gif
     
  9. Click on Ok.
  10. Now only the values which have CustomerID greater than 102 will be populated.

    filfindmetd18.gif

Up Next
    Ebook Download
    View all
    Learn
    View all