EntityDataSource.Select 属性
定义
获取或设置投影,该投影定义要包括在查询结果中的属性。Gets or sets the projection that defines the properties to include in the query results.
public:
property System::String ^ Select { System::String ^ get(); void set(System::String ^ value); };
public string Select { get; set; }
member this.Select : string with get, set
Public Property Select As String
属性值
用于创建 ORDER BY 子句的参数。The parameters that are used for creating the ORDER BY clause.
例外
当 Select 属性指定了查询投影且 EnableUpdate、EnableDelete 或 EnableInsert 的值为 true 时。When the Select property specifies a query projection and the value of EnableUpdate, EnableDelete, or EnableInsert is true.
示例
下面的 XML 标记使用 Select 属性指定具有该产品类型的六个属性的投影:The following XML markup uses the Select property to specify a projection with six of the properties of the Product type:
<asp:EntityDataSource ID="ProductDataSource" runat="server"
ConnectionString="name=AdventureWorksEntities"
DefaultContainerName="AdventureWorksEntities"
EntitySetName="Product" OrderBy="it.[ProductID]"
Select="it.[ProductID], it.[Name], it.[ListPrice],
it.[Size], it.[Style], it.[Weight]">
</asp:EntityDataSource>
上面的 XML 示例与下面命名的示例相同 ObjectQuery<T> products :The previous XML example is the same as the following ObjectQuery<T> named products:
ObjectQuery<Product> products = context.Product
.Select(it.[ProductID], it.[Name], it.[ListPrice],
it.[Size], it.[Style], it.[Weight])
.OrderBy("it.[ProductID]");
注解
Select控件的属性 EntityDataSource 包含一个字符串,该字符串表示实体 SQL 查询的SELECT语句。The Select property of the EntityDataSource control contains a string that represents the SELECT statement of an Entity SQL query. 这使您可以从查询返回的对象投影指定的属性集。This enables you to project a specified set of properties from the objects returned by the query.
此字符串将未经修改传递到 ObjectQuery<T> 实体框架执行的。This string is passed, without modification, to the ObjectQuery<T> that is executed by the Entity Framework. 此查询是控件控制的数据源 EntityDataSource 。This query is the source of the data regulated by the EntityDataSource control. 提供给属性的字符串 Select 使用的格式与传递到的方法的字符串相同 Select ObjectQuery<T> 。The string supplied to the Select property uses the same format as the string that is passed to the Select method of ObjectQuery<T>. 有关如何使用 SELECT 子句定义查询投影的示例,请参阅 如何:执行返回匿名类型对象的查询。For examples of how to use the SELECT clause to define a projection for a query, see How to: Execute a Query that Returns Anonymous Type Objects.
预计的数据不支持更新。Updates are not supported for projected data. 这意味着,当你使用 Select 属性指定投影时,绑定的数据绑定不支持更新。This means that when you use the Select property to specify a projection, the bound data binding does not support updates.
当定义启用了分页的投影时,必须定义用于对结果进行排序的属性。When you define a projection with paging enabled, you must define the property by which to order the results. 这意味着,当您将 Select 属性设置为定义投影并且 AutoPage 将设置为时 true ,您还必须设置 OrderBy 属性以定义顺序或将属性设置为,并向 AutoGenerateOrderByClause true 集合添加 order BY 参数 OrderByParameters 。This means the when you set the Select property to defined a projection and have AutoPage set to true, you must also set the OrderBy property to define the order or set the AutoGenerateOrderByClause property to true and add an ORDER BY parameter to the OrderByParameters collection.
Select 如果 EnableUpdate 启用了、或,则无法设置 EnableDelete EnableInsert 。Select cannot be set if EnableUpdate, EnableDelete, or EnableInsert is enabled.
如果 Select 设置为返回属性投影的查询 (例如, SELECT p.ProductID, p. Name FROM AdventureWorksEntities.Products AS p) ,则 DbDataRecord 将返回。If the Select is set to a query that returns a projection of properties (for example, SELECT p.ProductID, p. Name FROM AdventureWorksEntities.Products AS p), a DbDataRecord will be returned.