SIGN UP MEMBER LOGIN:    
ARTICLE

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

Posted by Vijai Anand Articles | SharePoint July 12, 2011
In this article we will be seeing how to create Comparison Filter Descriptor to a Finder Method.
Reader Level:

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 http://www.c-sharpcorner.com/UploadFile/anavijai/8234/?ArticleID=b718dc80-81fc-488e-9fbe-7202cd717175 . 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.

    public static IEnumerable<Customers> ReadList(int id)
            {
                MPDataContext dc =new MPDataContext(new Uri("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
                    select new 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

Login to add your contents and source code to this article
share this article :
post comment
 

Hello. Perfect article but please can you help me how can you call this from external source. For example I have this: IEntity entityDiskusia = catalog.GetEntity("HelpDeskProjectBDCModel.BdcModel1", "DiskusiaEntity"); ILobSystemInstance LobSysteminstanceDiskusia = entityDiskusia.GetLobSystem().GetLobSystemInstances()[0].Value; IMethodInstance methodDiskusia = entityDiskusia.GetMethodInstance("ReadList", MethodInstanceType.Finder); IFilterCollection filters = entityDiskusia.GetDefaultFinderFilters(); ComparisonFilter filter = (ComparisonFilter)filters[0]; filter.Value = "value"; IEntityInstanceEnumerator handleDiskusia = entityDiskusia.FindFiltered(filters, LobSysteminstanceKategoria); while (handleDiskusia.MoveNext()) { //Some code } This is working for me....But I am not sure if this is OK...I don't like this line: ComparisonFilter filter = (ComparisonFilter)filters[0]; Is possible to call filter by Name....My filer name is: ComparisonFilterDescriptor Hmm...Thank You for your help.

Posted by Vladimir Antalik Oct 21, 2011

Thank you..

Posted by Vijai Anand Jul 12, 2011

Helpful Article

Posted by Dea Saddler Jul 12, 2011
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor