Language preference:

Phase 3 / Overview of DataSource controls

DataSource controls interact with your database, providing the CRUD ("create, read, update, delete") actions that your DataBound controls use. This control knows the Entity class you are working with, the DataContext that contains it, and which methods that you created to handle each of the CRUD actions. Each also has ways to define the filters that limit the results of its queries.

  • EntityDAODataSource - This is the DataSource used with the BLD DataAccessObject classes.

    Select products based on the filtering user interface.
    <des:EntityDAODataSource ID="EntityDAODataSource1" runat="server"
       EntityTypeName="PeterBlum.WithDataAnnotations.Product"" 
       EnableUpdate="false" EnableInsert="false" EnableDelete="false">
       <EntityFilters>
          <des:FilterTemplatesEntityFilter ControlID="Filters1" />
       </EntityFilters>
    </des:EntityDAODataSource>
    Select one product based on its ID in the query string with support for editing it.
    <des:EntityDAODataSource ID="DataSource1" runat="server"  
       EntityTypeName="PeterBlum.WithDataAnnotations.Product" SelectMethod="SelectOne" 
       EnableUpdate="true" EnableInsert="false" EnableDelete="false"> 
       <SelectParameters> 
          <des:SmartSelectParameter QueryStringField="ID" /> 
       </SelectParameters> 
    </des:EntityDAODataSource>
  • EntityDataSource - When you don't use Data Access Objects but use ADO.NET Entity Framework, use this DataSource control. Be sure to use the one supplied in BLD, not the native one. BLD's is a subclass of the native control that provides extensions to handle EntityFilters.
    <des:EntityDataSource ID="EntityDAODataSource1" runat="server"
       EntitySetName="PeterBlum.WithDataAnnotations.Product"" 
       EnableUpdate="false" EnableInsert="false" EnableDelete="false">
       <EntityFilters>
          <des:FilterTemplatesEntityFilter ControlID="Filters1" />
       </EntityFilters>
    </des:EntityDataSource>
    <des:EntityDataSource ID="DataSource1" runat="server"  
       EntitySetName="PeterBlum.WithDataAnnotations.Product" SelectMethod="SelectOne" 
       EnableUpdate="true" EnableInsert="false" EnableDelete="false"> 
       <EntityFilters>
          <des:UIDataFieldsFinderEntityFilter/>
       </EntityFilters>
    </des:EntityDataSource>
  • LinqDataSource - When you don't use Data Access Objects but use LINQ to SQL, use this DataSource control. Be sure to use the one supplied in BLD, not the native one. BLD's is a subclass of the native control that provides extensions to handle EntityFilters.
    <des:LinqDataSource ID="EntityDAODataSource1" runat="server"
       EntityTypeName="PeterBlum.WithDataAnnotations.Product"" 
       EnableUpdate="false" EnableInsert="false" EnableDelete="false">
       <EntityFilters>
          <des:FilterTemplatesEntityFilter ControlID="Filters1" />
       </EntityFilters>
    </des:LinqDataSource>
    <des:LinqDataSource ID="DataSource1" runat="server"  
       EntityTypeName="PeterBlum.WithDataAnnotations.Product" SelectMethod="SelectOne" 
       EnableUpdate="true" EnableInsert="false" EnableDelete="false"> 
       <EntityFilters>
          <des:UIDataFieldsFinderEntityFilter/>
       </EntityFilters>
    </des:LinqDataSource>
  • ObjectDataSource - When you use Data Access Objects but they are not based on BLD DataAccessObjects, use this DataSource control. Be sure to use the one supplied in BLD, not the native one. BLD's is a subclass of the native control that provides extensions to handle EntityFilters and to let URL Routing determine the value of the DataObjectTypeName property.
    <des:ObjectDataSource ID="ObjectDataSource1" runat="server" 
         OnObjectCreating="ObjectDataSource1_ObjectCreating"
         TypeName="BLL.SampleEntityDAO" DataObjectTypeName="BLL.SampleEntity" 
         SelectMethod="Select" UpdateMethod="Update" />
  • POCODataSource - This BLD-specific control lets you turn any class into a business object. (POCO stands for "Plain Old CLR Object"). You can use DataAnnotations like ValidationAttributes and DataTypeAttributes on properties of your objects. The DataBound control will create a user interface that respects the DataAnnotations.
    <asp:POCODataSource ID="POCODataSource1" runat="server" POCOTypeName="EmailGeneratorArgs" />
    public class EmailGeneratorArgs
    {
       public EmailGeneratorArgs() { }
    
       [DESDA.Required()]
       [DESDA.EmailAddressDataType(DataType.EmailAddress)]
       public string FromEmailAddress { get; set; }
       [DESDA.Required()]
       [DESDA.EmailAddressDataType(DataType.EmailAddress)]
       public string ToEmailAddress { get; set; }
       [DESDA.Required()]
       [DESDA.StringLength(80)]
       public string Subject { get; set; }
       [DESDA.Required()]
       [DESDA.StringLength(5000)]
       [DataType(DataType.MultilineText)]
       public string Body { get; set; }
       [DataType(DataType.Date)]
       public DateTime SendDate { get; set; }
       [Browsable(false)]
       public int RetryNumber{ get; set; }
    }
    

BLD is flexible enough to handle other types of DataSources. All DataSource classes have an associated subclass of PeterBlum.DES.BLD.BaseDataSourceAdapter. So if you need to use another DataSource, create a DataSourceAdapter class.

BLD includes DataSourceAdapters to let you use data from a System.Data.DataTable with full business logic support, and for your own Entity classes without a real DataSource control. In that case, you will handle the DataBound control's CRUD event handlers fully to interact with your database and generate or write Entity instances.

In the next topic, you'll learn about the BLDPageManager control and its DataBound Control Adapter classes.