How to: Add a Filter Descriptor to a Finder Method

Filter descriptors enable consumers of the model to pass values to methods before they execute. For more information, see Designing a Business Data Connectivity Model.

One common scenario is that users in SharePoint want to retrieve instances of an external content type that match some criteria. You can support this scenario by adding a filter descriptor to a Finder method.

To add a filter descriptor to a Finder method

  1. In the BDC Method Details window, expand the node of a Finder method, expand the Parameters node, and then add an input parameter. For more information, see How to: Add a Parameter to a Method.

  2. In the Method Details window, select the type descriptor of the parameter.

  3. On the View menu, click Properties Window.

  4. In the Properties window, set the Type Name property to a data type that is appropriate for the filter.

    For example, a filter might use an order date to limit the number of sales orders returned by the method. To support that filter, the Type Name property of the type descriptor must be set to System.DateTime.

  5. In the Method Details window, expand the Filter Descriptors node.

  6. In the Add a Filter Descriptor drop-down list, click Create Filter Descriptor.

    A new filter descriptor appears underneath the Filter Descriptors node.

  7. On the View menu, click Properties Window.

  8. In the Properties window, select the Type property.

  9. In the drop-down list that appears for the Type property, select the filtering pattern that you want. For more information about each filtering pattern, see Types of Filters Supported by the BDC.

    For example, to create a filter that uses an order date to limit the number of sales orders returned in a Finder method, select Comparison. A Comparison filter limits the instances returned by a finder method to those where a specific condition is met.

  10. In the Properties window, select the Associated Type Descriptors property.

  11. In the drop-down list that appears for the Associated Type Descriptors property, select the type descriptor that you created earlier in this procedure. This relates the filter to the input parameter of the Finder method.

  12. Add code to the Finder method that returns data. You can use the input parameter as a condition in a select query.

    The following example returns sales orders that have the specified order date.

    NoteNote

    Replace the value of the ServerName field with the name of your server.

    
    public static IEnumerable<SalesOrderHeader> ReadList(DateTime OrderDateParam)
    {
        const string ServerName = "MySQLServerName";
        AdventureWorksDataContext dataContext = new AdventureWorksDataContext
              ("Data Source=" + ServerName + ";" +
               "Initial Catalog=AdventureWorks;Integrated Security=True");
    
        DateTime NoValuePassedIn = Convert.ToDateTime("1/1/1900 12:00:00 AM");
        DateTime DefaultDateTime = Convert.ToDateTime("2001-09-01 00:00:00.000");
    
        // If the user does not provide a value for the filter.
        if (OrderDateParam == NoValuePassedIn)
        {
            // Use a default date time value.
            OrderDateParam = DefaultDateTime;
        }
    
        IEnumerable<SalesOrderHeader> SalesOrderHeader =
            from salesOrderHeaders in dataContext.SalesOrderHeaders
            where salesOrderHeaders.OrderDate == OrderDateParam
            select salesOrderHeaders;
        return SalesOrderHeader;
    }
    
    
    
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft