Use a filter using the BCS Object Model

Source: Internet
Author: User
ArticleDirectory
    • Procedure

In the previous blog, we introduced how to use the business connection service object model on the Sharepoint Server to connect to the BCS service metadata storage to obtain the object, external content type, and methods of an enterprise's core business system, and how to execute an external content type method.

Execute the BCS external content type method in the C # code

This document describes how to execute a finder method with an external content type defined by a filter.

Procedure

1. Use SharePoint designer 2010 to create a new external content type and use the Employees table of the adventureworks2000 database. Set a filter for this ECT in the first name column.

Note that the check box "ignore filter if it is of the following values" is selected ".

2. Open Visual Studio 2010 and select create a "Visual Web parts" project from the sharepoint2010 project category.

3. In the design mode of the webpart user control, add some text "First name :". Drag and Drop a text box and a button. Set the text box ID to firstnametextbox, and the button ID to searchbutton. Finally, add a gridview. The completed interface is shown in the following figure:

 

4. Add a reference to Microsoft. businessdata. dll, right-click the reference folder in Solution Explorer, and select Add reference ". Browse to this dll:

C: \ Program Files \ common files \ microsoft shared \ Web Server Extensions \ 14 \ ISAPI \ Microsoft. businessdata. dll

5. Open the user control -- visualwebpart1usercontrol. ascx. CS and add the following using statement:

Using Microsoft. SharePoint;
Using Microsoft. Sharepoint. businessdata. sharedservice;
Using Microsoft. businessdata. metadatamodel;
Using Microsoft. Sharepoint. administration;
Using Microsoft. businessdata. runtime;
Using Microsoft. Sharepoint. businessdata. runtime;

6. Add the following methods:

Private   Void Executefiltermethod ()
{
// Get the object directory to start our work
Bdcservice Service =   Spfarm . Local. Services. getvalue < Bdcservice > ();
Imetadatacatalog Catalog = Service. getdatabasebackedmetadatacatalog ( Spservicecontext . Current );
// Obtain the external content type of the employee
Ientity Entity = Catalog. getentity ( " Http: // contoso14 " , " Employee " );
// Obtain the filter of the default finder method.
Ifiltercollection Filters = Entity. getdefafinfinderfilters ();
// If firstnametextbox has a value, set the filter value.
If (Firstnametextbox. Text ! =   String . Empty)
{
Wildcardfilter Filter = ( Wildcardfilter ) Filters [ 0 ];
Filter. Value = Firstnametextbox. text;
}
// Use the default finder method to return filtered data
Ientityinstanceenumerator Enumerator = Entity. findfiltered (filters, entity. getlobsystem (). getlobsysteminstances ()[ 0 ]. Value );

Datatable Table =   Null ;

// Loop traversal of returned data
While (Enumerator. movenext ())
{
// Set the data table for the first time, and then add rows directly.
If (Table =   Null )
Table = Enumerator. Current. entityasdatatable;
Else
Table. importrow (enumerator. Current. entityasdatatable. Rows [ 0 ]);
}
// Bind data to our gridview
Gridview1.datasource = Table;
Gridview1.databind ();

}

7. Double-click the button on our user control to add a click event processingProgram, The content is very simple, just call the above method:

Protected   Void Searchbutton_click ( Object Sender, eventargs E)
{
Executefiltermethod ();
}

8. AllCodeThe work is complete. Now we can press F5 to run it. Visual Studio will pack us into a WSP package and deploy it to our website.

When Sharepoint is enabled, enter the page editing mode and insert a webpart. Our visualwebpart1 is located in the M group. After adding the content, click the button and you will return all data from the external content type of the employee. Alternatively, you can enter a first name such as Linda to return results that meet the conditions:

In the following article, we will further introduce the object model of BCS.

 

References

Using filters and the Business connectivity services object model

Creating a web service to access BCS data in SharePoint 2010

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.