Configuring the EntityDataSource Control
Updated: July 2008
The EntityDataSource control simplifies the binding of data that is defined by an Entity Data Model (EDM) to controls in an ASP.NET Web application by taking advantage of the Object Services components of the ADO.NET Entity Framework. This enables the control to compose and execute object queries and bind controls to the returned objects, which are instances of entity types that are defined in the EDM. For more information, see Object Services Overview (Entity Framework).
You must configure the properties of the EntityDataSource control to be able to connect to the EDM and return the correct entity types. When you set the ConnectionString and DefaultContainerName properties, the EntityDataSource control can create the ObjectContext it uses to execute object queries. When you set the EntitySetName and EntityTypeFilter properties, you define the type of ObjectQuery<(Of <(T>)>) that the EntityDataSource control composes.
You can initialize the ConnectionString property of the EntityDataSource control from a named EDM connection string stored in the connectionStrings element of the application configuration file. When you create the EDM by using the Entity Data Model Wizard, you create a named EDM connection in the application configuration file. You can then view this connection as an option in the Configure Data Source wizard of the EntityDataSource designer. For more information, see Configure Data Source Wizard (EntityDataSource Control).
In Object Services, a typed ObjectContext represents the entity container of the conceptual model. The ObjectContext class is the primary class for interacting with data defined by an EDM. This data is in the form of objects that are instances of entity types. A typed ObjectContext encapsulates a connection to the database, metadata that describes the model, and an ObjectStateManager object that tracks objects during create, update, and delete operations. The ContextTypeName property of the EntityDataSource control is a string that specifies the fully qualified type name of the typed ObjectContext that the EntityDataSource control uses. If the ContextTypeName property is not specified, you must set both the DefaultContainerName and ConnectionString properties for the EntityDataSource control to create the ObjectContext. You can access the ObjectContext that the EntityDataSource control uses from the ContextType property. For more information, see Object Context Life-Cycle Management (EntityDataSource).
In the EDM, an entity set is a logical container for entity types that are defined in the conceptual schema. You can specify the entity set of the type of objects that the EntityDataSource control accesses through the EntitySetName. The value of the EntitySetName property is the default SELECT statement that the control uses. The setting is not required if the query is specified as an Entity SQL expression supplied to the CommandText property. For more information, see Custom Command Text (EntityDataSource).
When the EntityDataSource control must return a specific derived type, you must also specify the name of this derived type in the EntityTypeFilter property. If the EntitySetName property specifies an entity set that can generate polymorphic results, the EntityTypeFilter property is required to be able to edit data. Setting the EntityTypeFilter property has the same effect as applying the OfType<(Of <(TResultType>)>) method to the ObjectQuery<(Of <(T>)>). If the data binding is read-only then the EntityTypeFilter property is not required. In this case, the properties of the object that the query returns will be those of the default entity type for the entity set.