共用方式為


Human Resources ASP.NET Web Site (EDM Sample Application)

The Human Resources ASP.NET application is an interface that can be used on a network or the Internet to display data that is defined and compiled by using the example: Human Resources Skills WinApp (EDM Sample Application).

Downloading and Running the Sample

The Human Resources Skills ASP.NET sample is available on the ADO.NET Entity Framework Documentation Samples resource page in MSDN Code Gallery. Requirements and instructions for building and running the sample are provided in the readme.htm file in the download package.

Note

The published solution also contains a project for the Human Resources Skills WinApp (EDM Sample Application). This Windows Forms application is used to enter the data into the HRSkills database.

Design

The data model and database that this Web application uses are the same as those used by the Windows Forms application. This Web application uses instances of the EntityDataSource control to provide entity data that is bound to the Web controls.

The Web site is built in three stages:

  1. Create a GridView control and associated EntityDataSource control on the Web page for each of the following entities:

    • Employees

    • Skills

    • SkillInfo

    • References

  2. Write the logic that creates an ObjectQuery<Skills> that returns Skills based on the search criteria along with the related Employees, References, and SkillInfo objects, and binds the collection of Employees to the GridView.

  3. Configure IIS to run the ASP.NET application and connect to data that is stored on the instance of SQL Server that the HRSkills application uses.

Related Skills, References, and SkillInfo objects are displayed for a selected Employees object in the EmployeeGridView. This filtering is accomplished by means of a parameterized WHERE clause with a WhereParameter that is based on the selected value of the EmployeeGridView. A default GUID value of EmployeeID is set to ensure that no Skills or References are displayed until the user selects an employee.

Entity Framework Features

This sample demonstrates the following features of the Entity Framework.

  • Entity Data Model (EDM)
    The sample uses a data model that is based on the HRSkills database. The model was generated using the Entity Data Model tools and is maintained in the HRSkills.edmx file in the Visual Studio project. To review the HRSkills data model, open this model file in the Entity Data Model Designer in Visual Studio and open the Model Browser and Mapping Details windows.
  • EntityDataSource control
    The EntityDataSource control is a Web server data source control that enables data binding to entity data in ASP.NET applications by automatically executing queries and returning entity data as objects that can be bound to Web controls on the page.
  • Data binding
    An EntityDataSource is defined for each entity type that is bound to a GridView control. These data sources enable data bindings to be defined in Visual Studio. For more information, see How to: Bind Web Controls to an EntityDataSource.
  • Query builder methods
    The skill search functionality does not use the EntityDataSource. Instead query builder methods of ObjectQuery are used to filter the returned skills. The related Employees object is loaded from each returned Skills object, and these Employees are bound to the EmployeeGridView. Query builder methods are methods of ObjectQuery that can be used to sequentially construct query commands that are equivalent to Entity SQL. For more information, see Query Builder Methods (Entity Framework).

See Also

Other Resources

Sample Applications (Entity Framework)