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 chooses 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
On the BDC designer, choose an entity.
For information about how to add an entity to the BDC designer in Visual Studio, 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 that window, see BDC Model Design Tools Overview.
In the Add a Method list, choose 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.
Open the Visual Studio Properties window.
Configure the type descriptor of the return parameter as an entity type descriptor. For information about how to create an entity type descriptor, see How to: Define the Type Descriptor of a Parameter.
Note
You don't 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.
Note
If the identifier field of the entity type represents a field in a database table that's automatically generated, set the Read-only property of the identifier field to True.
In the Method Details window, choose the method instance of the method.
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.
In Solution Explorer, open the shortcut menu of the service code file that was generated for the entity, and then choose 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.
Add code to the Specific Finder method. This code performs the following tasks:
Retrieves a record from a data source.
Returns an entity to the BDC service.
The following example returns a contact 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 ReadItem(ByVal contactID As Integer) As Contact Const ServerName As String = "MySQLServerName" Dim dataContext As AdventureWorksDataContext = _ New AdventureWorksDataContext("Data Source=" & ServerName & _ ";Initial Catalog=AdventureWorks;Integrated Security=True") Dim Contact As Contact = _ (From TempContacts In dataContext.Contacts.AsEnumerable().Take(20) _ Where TempContacts.ContactID = contactID _ Select TempContacts).[Single]() Return Contact End Function
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; }
See Also
Tasks
How to: Add a Parameter to a Method
How to: Define a Method Instance
Concepts
BDC Model Design Tools Overview