How to: Add a Finder Method

To enable the Business Data Connectivity service to display a list of entities in a Web Part or list, you must create a Finder method. A Finder method is a special method that returns a collection of entity instances. For more information, see Designing a Business Data Connectivity Model.

To create a Finder method

  1. On the BDC designer, select an entity. For more information about how to add an entity to the BDC designer in Visual Studio. For more information, see How to: Add an Entity to a Model.

  2. On the View menu, click Other Windows, and then click BDC Method Details.

    The BDC Method Details window opens. For more information about the BDC Method Details window, see BDC Model Design Tools Overview.

  3. In the BDC Method Details window, from the Add a Method drop-down list, select Create Finder Method.

    Visual Studio adds a method, a return parameter, and a type descriptor.

  4. Configure the type descriptor as an entity collection type descriptor. For more information about how to create an entity collection type descriptor, see How to: Define the Type Descriptor of a Parameter.

    Note

    You do not have to perform this step if you have added a Specific Finder method to the entity. Visual Studio uses the type descriptor that you defined in the Specific Finder method.

  5. In Solution Explorer, right-click the service code file that was generated for the entity, and then click View Code. For more information about the service code file, see Creating a Business Data Connectivity Model.

  6. Add code to the Finder method. This code will perform the following tasks:

    • Retrieve data from a data source.

    • Return a list of entities to the BDC service.

    The following example returns a collection of Contact entities by using data from the AdventureWorks sample database for SQL Server.

    Note

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

    Public Shared Function ReadList() As IEnumerable(Of Contact)
        Const ServerName As String = "MySQLServerName"
        Dim dataContext As AdventureWorksDataContext = _
            New AdventureWorksDataContext("Data Source=" & ServerName & _
                ";Initial Catalog=AdventureWorks;Integrated Security=True")
    
        Dim Contacts As IEnumerable(Of Contact) = _
            From TempContacts In dataContext.Contacts.Take(20) _
                  Select TempContacts
        Return Contacts
    End Function
    
    public static IEnumerable<Contact> ReadList()
    {
        const string ServerName = "MySQLServerName";
        AdventureWorksDataContext dataContext = new AdventureWorksDataContext
              ("Data Source=" + ServerName + ";" +
               "Initial Catalog=AdventureWorks;Integrated Security=True");
    
        IEnumerable<Contact> Contacts =
            from contacts in dataContext.Contacts.Take(20)
            select contacts;
        return Contacts;
    
    }
    

See Also

Tasks

How to: Add a Specific Finder Method

How to: Add a Creator Method

How to: Add a Deleter Method

How to: Add an Updater Method

How to: Add a Parameter to a Method

How to: Define a Method Instance

Concepts

BDC Model Design Tools Overview

Other Resources

Designing a Business Data Connectivity Model