How to: Add a specific Finder method
Applies to: Visual Studio Visual Studio for Mac
Note
This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here
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 Design 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 Design 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 Create 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 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; }
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