Gets or sets the name of the property or field in the data context class that represents a data collection.
Assembly: System.Web.Extensions (in System.Web.Extensions.dll)
Set the property to the name of the property or field that represents the data that you want to retrieve. When you are connecting to a database table, the name of the property is usually the same as the name of the table. When you are connecting to an in-memory data collection, set the property to the name of the property or field that returns the data collection.
You can assign a property that returns any type to the property for retrieval operations. If the object that is represented by the property does not implement IEnumerable, the LinqDataSource control will automatically wrap the object in an instance of an IEnumerable object.
To enable automatic update, insert, or delete operations, the class that is assigned to the ContextTypeName property must derive from DataContext and the property that is assigned to the property must derive from Table(Of TEntity).
For information about how to select data from an instance of a class, see the Result property.
The following example shows two LinqDataSource controls. In one LinqDataSource control, the property is set to a property in a class. That property returns an array of strings. In the other LinqDataSource control, the property is set to a property that represents a database table.
<!-- Retrieve and display data from array of string values --> <asp:LinqDataSource ContextTypeName="MovieLibrary" TableName="AvailableGenres" ID="LinqDataSource1" runat="server"> </asp:LinqDataSource> <asp:DropDownList DataSourceID="LinqDataSource1" runat="server" ID="DropDownList1"> </asp:DropDownList> <!-- Retrieve and display data from database --> <asp:LinqDataSource ContextTypeName="ExampleDataContext" TableName="Movies" Select="Title" ID="LinqDataSource2" runat="server"> </asp:LinqDataSource> <asp:DropDownList DataSourceID="LinqDataSource2" runat="server" ID="DropDownList2"> </asp:DropDownList>
The class named ExampleDataContext that represents the database table is not shown in this example. For this example to work, you must create this class by adding a LINQ to SQL class named Example.dbml and dragging a table named Movie onto the O/R Designer. A class named ExampleDataContext with a property named Movies is generated.
The following example shows the class named MovieLibrary that is referenced in the LinqDataSource control.