Welcome back! We hope that you have successfully created your own entity by following the previous steps in building a business data connection service model in Visual Studio 2010 and deployed it on SharePoint.
This time, we will continue to expand our BCS model. We will create the specificfinder and idenumerator methods on the department entity. First, set specificfinder...
1. Right-click the methods section of our department object and select Add new method. Name the method getdepartmentbyid.
2. Open departmentservice. CS and you will see that a new method has been created for us. Modify the declaration of this method so that it can receive a parameter and return a department object.
Public Static Department getdepartmentbyid (int16 interval mentid)
3. Add the following in your method:CodeTo replace the default not implemented exception:
Code
Departmentdatacontext DB = New Departmentdatacontext
( " Server = localhost; database = adventureworks2000; uid = ***; Pwd = *** " );
VaR dbdepartment = DB. Orders ments. singleordefault (d => D. initialize mentid = Departmentid );
Return New Department
{
Departmentid = Dbdepartment. Dimension mentid,
Name = Dbdepartment. Name,
Groupname = Dbdepartment. groupname
};
We need to do more work, because we want to return our own department class, instead of the one generated by LINQ 2 SQL. The reason has been explained in the first article. I personally think this is a correct path.
4. Next we need to modify our BCS model. Return to our bcs model page and click the getdepartmentbyid method. On the BCS method details panel, select Add a parameter. Select your new parameter and change its name to required mentid on the property panel. Click type descriptor under it and set the following values:
Name: Required mentid
Type name: system. int16
Identifier: specified mentid
5. Then we will create the response parameters. Return to the BDC method details panel and select create another parameter under the getdepartmentbyid method.
6. in BDC explorer, select the new parameter, change the name to department, and set the parameter direction to return.
7. It is time to reflect the superiority of BDC explorer. Expand the getdepartments method of our department object. Right-click the Department type descriptor and select copy. Right-click the Department parameter of the getdepartmentbyid method and select Paste.
A dialog box is displayed asking whether to overwrite the existing type descriptor -- click "yes ". At this time, you will find that both the Department type descriptor and the type descriptor of all fields are copied. This reduces some manual creation work.
Result:
Note that if the copied type descriptor has some errors, these errors will also be copied to other methods. That's why it is best to build
After the finder method is tested correctly, copy and paste the type descirptor.
8. Now we only need to create a Method Instance. Return to the BDC method details panel, and select Add a Method Instance under the getdepartmentbyid method. Set the property value:
Type: specificfinder
Default: True
Default display name: single department
Return Parameter Name: Department
Return type descriptor: Department
9. Before testing and deployment, we need to clear the redundant code in our departmentservice. CS class.
The BCS designer wants you to define your methods, parameters, and type descriptors before writing code. This is exactly why the returned object and
After the input parameters are entered, a new method declaration is generated. I prefer to write code first and then build the BCS model. If you follow the same steps as me, be sure to check
Service class to clear useless method code.
10. After the WSP is cleared, run F5 to compile and deploy the WSP to SharePoint.
You can test the specific finder method by adding and configuring a business data entry webpart. Alternatively, you can create an external table list and click a row to view the form for verification.
11. Our specific finder BCS method works normally! Now let's return to Visual Studio to configure our idenumerator method. Right-click the Department object's methods section and add a method named getdepartmentids.
12. Enter the departmentservice. CS class and modify the declaration of the getmediamentids method:
Public Static Ienumerable < Short > Getdepartmentids ()
13. Remember, our idenumerator method only supports returning the value of the primary key in the field. SharePoint creates indexes and crawls the network. The code for this method is simple:
Departmentdatacontext DB = New Departmentdatacontext
("Server = localhost; database = adventureworks2000; uid = ***; Pwd = ***");
ReturnFrom dInDB. analytics
Select D. Explain mentid;
14. Now we are building the BCS model to reflect the returned data. Switch back to the BCS Model View. Select the getdepartmentids method and create a parameter in the BDC details panel.
15. Expand the tree in BDC explorer and select the created parameter. In the Property panel, change the direction to return.
16. Select parametertypedescriptor under our parameters and set its value:
Name: receivmentids
Type name: system. Collections. Generic. ienumerable '1 [[system. int16]
Iscollection: True
17. Right-click the departmentids type descriptor node in the tree and select Add type descriptor. Set the attributes of this type descriptor:
Name: Required mentid
Type name: system. int16
Identifier: specified mentid
18. Finally, add a methodinstance for our method. On the BDC method details panel, click Add a Method Instance. Select the Method Instance and set its property value:
Type: idenumerator
Default: True
Return Parameter Name: Parameter
Return type descriptor: extends mentids
Remember to clear the getinclumentids method created during the modeling process in departmentservice. CS.
19. We want to make our lobsysteminstance into an application that can be crawled by the SharePoint 2010 indexer.Program, You also need to set a new attribute for it. This attribute is named showinsearchui.
Expand the BCS model in BDC explorer and find the lobsysteminstance node.
20. On the property panel, set a custom property named showinsearchui and the type is system. String. This attribute does not actually need a value, but only needs to exist.
21. That's all. Now we can press F5 to package our model into a WSP and deploy it to SharePoint. Here, we also have some special steps in the SharePoint UI to display our pieces of data in the search results.
22. In the original BDC (business data catalog), the configuration file page of your object is automatically created. The configuration file page is not automatically created in BCS using the above steps. Therefore, we need to create one step manually. Open the SharePoint 2010 management center and Click Manage service applications. On the service application page, click business data connectivity service to link to its management page.
23. On the functional area, click Edit Tag and click Configure. In the pop-up form, we need to enter a host URL on the configuration file page. As explained in the page, it is best to create a separate website to host these configuration file pages, but here we will directly enter the same URL, pointing to our SharePoint site, for me, it is http: // sp2010u.
Click OK to close the form.
24. Now, we can create a configuration file page on our external content type. Hover your mouse over our department ECT and select "Create/upgrade configuration file" from the drop-down menu ".
Click OK in the displayed dialog box. Now, the configuration file page is created to the host website specified in Step 23.
25. Next we will check whether our entities can be crawled. Click Department ECT and check that the "crawling" attribute value is "yes ".
26. Now, we need to set our BCS application as a search content source. Return to the Application Management page and click the search service application link.
27. Click the "content source" link in the left-hand navigation menu, and then click the new content source link on the next page.
28. Name the new content source and set the data type to line of business data ). After clicking the button, the interface is refreshed and the following section is displayed to show external data sources. Select the BCS application system for network crawling. This is bdcmodel1.
NOTE: If your application system does not appear here, check whether showinsearchui has been added to the attribute set. (AvailableSource codeOpen the model file in the editor instead of the default model editing interface. Check whether showinsearchui is available in the attribute set under the lobsysteminstance node ).
29. You can set up a network crawling plan if you like. Finally, select "start full crawling for this content source" and click "OK.
30. When the crawling is complete, check the crawling logs of the BCS content source.
You can see 18 successful entries, one for each department.
31. If you already have a working group site as the root site of the website set, you need to create a search center site. After the creation, go to the search center site and search for a keyword "engineering". Then you will see the result returned by engineering department with Department ect.
32. You can link the search center to your workgroup website. Return to the workgroup site and click
Website operations-> website settings-> Search Settings
You can paste the URL of the search center here to use the result page.
Wow -- cheer for yourself! As a series, we will introduce how to create an association.
References
BCS model in Visual Studio 2010-specificfinder and idenumerator
Searching external data in SharePoint 2010 using business connectivity services
BDC. Net Assembly connector: tame SharePoint search to search your. Net BDC entity
Search-specific properties in BDC model files