Gets or sets the properties and calculated values that are included in the retrieved data.
Assembly: System.Web.Extensions (in System.Web.Extensions.dll)
If you do not set the property, the LinqDataSource control retrieves all the properties (data columns) from the data object. You use the property to retrieve a subset of properties from the object or to calculate new values when the data is being retrieved.
You specify which properties to retrieve by setting the property to the names of the properties that you want to include in the returned data.
If you retrieve a subset of properties from the data object, the LinqDataSource control dynamically creates a class that contains only the properties that you specify in the property. A class is also created dynamically if you calculate properties that are not properties in the data object. In these cases, the object returned from the query is not an instance of the class that is specified in the TableName property. Instead, you must use the new method in the property to indicate that a new class is returned from the query. For example, to return only the FirstName and LastName properties from an object that contains more than these properties, set the property to new(FirstName, LastName). The LinqDataSource control will dynamically create the new class that you specified in the new method.
You can use the As keyword to assign an alias to a selected value. If you assign an alias, you must include the aliased properties in the new method. Any data-bound control that binds to the results from the LinqDataSource control must refer to the property by the alias. For example, if you set the property to new(Region As SalesRegion, Revenue / 1000 As RevenueThousands), the data-bound control can access two properties, SalesRegion and RevenueThousands.
You use the new function in the property according to the conditions listed in the following table.
Use of new
new not needed.
Single or multiple properties that have an alias.
Select="new(Category As CategoryGroup)"
If you want to enable automatic data modifications, but you do not want to display all the properties from the data object, do not set the property. Instead, manage the display through the data-bound control. When you use the DetailsView control or the GridView control, you must also set the AutoGenerateRows or the AutoGenerateColumns property to false. Any values that are not displayed in the data-bound control are stored in view state. They are passed unchanged to the data source when the data update is performed.
When you group data in the query, you can include aggregate methods in the property. You can use the following aggregate methods:
For more information, see LinqDataSource Web Server Control Overview and How to: Group and Aggregate Data Using the LinqDataSource Control.
When you group data, you can include Key and It, which are dynamically created properties, in the property. The Key property refers to the values in the property or properties that were used to group the data. For example, if you group by a property named Category, the Key property will contain each unique value in the Category property. The It property refers to a collection of individual records in a grouping of data. You can iterate over the It property to retrieve the individual records that have been consolidated in the grouping operation. For example, if you group by a property named Category, the It property contains all the individual records that share a common value in the Category property.
If you include the It keyword in the property when you group data, you must assign an alias to the It keyword. The LinqDataSource control will throw an exception if It does not have an alias. You can assign an alias to the Key keyword, but this is not required.
The following example shows how to set the property to a subset of properties in the data object.
The following example shows how to retrieve values in a property that has been used to group data, and to retrieve the average for the grouped records. The Key keyword contains the property that has been used for grouping data. In this example, Key will contain the shared values from the ProductCategory property.
Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.