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
On the BDC designer, choose an entity.
For more information, see How to: Add an Entity to a Model.
On the menu bar, choose View, Other Windows, BDC Method Details.
The BDC Method Details window opens. For more information about the BDC Method Details window, see BDC Model Design Tools Overview.
In the Add a Method list, choose Create Finder Method.
Visual Studio adds a method, a return parameter, and a type descriptor.
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.
In Solution Explorer, open the shortcut menu of the service code file that was generated for the entity, and then choose View Code. For more information about the service code file, see Creating a Business Data Connectivity Model.
Add code to the Finder method. This code performs the following tasks:
Retrieves data from a data source.
Returns 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 Parameter to a Method
How to: Define a Method Instance
Concepts
BDC Model Design Tools Overview