This documentation is archived and is not being maintained.

How to: Add a Specific Finder Method

You can return a single entity instance by creating a Specific Finder method. The Business Data Connectivity (BDC) service executes the Specific Finder method when a user selects an entity in a Business Data Web Part or External list. For more information, see Designing a Business Data Connectivity Model.

To create a Specific 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 Specific Finder Method.

    Visual Studio adds the following elements to the model. These elements appear in the BDC Method Details window.

    • A method.

    • An input parameter for the method.

    • A return parameter for the method.

    • A type descriptor for each parameter.

    • A method instance for the method.

    For more information, see Designing a Business Data Connectivity Model.

  4. Open the Visual Studio Properties window.

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

    NoteNote

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

    NoteNote

    If the identifier field of the entity type represents a field in a database table that is automatically generated, set the Read-only property of the identifier field to True.

  6. In the Method Details window, select the method instance of the method.

    By default, Visual Studio names this method MethodInstance1.

  7. In the Properties Window, set the Return Parameter Name property to the name of the return parameter of the method. For more information about method instance properties, see MethodInstance.

  8. In Solution Explorer, right-click the service code file that was generated for the entity, and then click View Code.

    The entity service code file opens in the Code Editor. For more information about the entity service code file, see Creating a Business Data Connectivity Model.

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

    • Retrieve a record from a data source.

    • Return an entity to the BDC service.

    The following example returns a contact from the AdventureWorks sample database for SQL Server.

    NoteNote

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

    
    public static Contact ReadItem(int contactID)
    {
        const string ServerName = "MySQLServerName";
        AdventureWorksDataContext dataContext = new AdventureWorksDataContext
              ("Data Source=" + ServerName + ";" +
               "Initial Catalog=AdventureWorks;Integrated Security=True");
    
        Contact Contact =
            (from contacts in dataContext.Contacts.AsEnumerable().Take(20)
             where contacts.ContactID == contactID
             select contacts).Single();
        return Contact;
    }
    
    
    
Show: