LinqDataSourceSelectEventArgs.Result Propiedad
Definición
Obtiene o establece el objeto de datos que se utiliza en la consulta de datos.Gets or sets the data object that is used in the data query.
public:
property System::Object ^ Result { System::Object ^ get(); void set(System::Object ^ value); };
public object Result { get; set; }
member this.Result : obj with get, set
Public Property Result As Object
Valor de propiedad
Objeto que representa los datos de la consulta.An object that represents the data for the query.
Ejemplos
En el ejemplo siguiente se muestra cómo establecer la Result propiedad en el resultado de una consulta LINQ.The following example shows how to set the Result property to the result of a LINQ query.
protected void LinqDataSource_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{
ExampleDataContext exampleContext = new ExampleDataContext();
e.Result = from p in exampleContext.Products
where p.Category == "Beverages"
select new {
ID = p.ProductID,
Name = p.Name
};
}
Protected Sub LinqDataSource_Selecting(sender As Object, e As LinqDataSourceSelectEventArgs)
Dim exampleContext As New ExampleDataContext()
e.Result = From p In exampleContext.Products Where p.Category = "Beverages"
Select New With { _
Key .ID = p.ProductID, _
Key .Name = p.Name _
}
End Sub
En el ejemplo siguiente se muestra cómo establecer la Result propiedad en una matriz de valores de cadena que se define en la Página Web.The following example shows how to set the Result property to an array of string values is defined in the Web page.
public partial class Default3 : System.Web.UI.Page
{
string[] citiesArray =
{
"Atlanta",
"Charlotte",
"Denver",
"New York",
"San Francisco"
};
protected void Page_Load(object sender, EventArgs e)
{
}
protected void LinqDataSource_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{
var cities = from city in citiesArray
where city.CompareTo("B") > 0
select city;
e.Result = cities;
// Or we could set e.Result = citiesArray to return all rows.
}
}
Partial Class Default3
Inherits System.Web.UI.Page
Dim citiesArray() As String = _
{ _
"Atlanta", _
"Charlotte", _
"Denver", _
"New York", _
"San Francisco" _
}
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub LinqDataSource_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LinqDataSourceSelectEventArgs) Handles LinqDataSource1.Selecting
Dim cities = From city In citiesArray _
Where city > "B" _
Select city
e.Result = cities
' Or we could set e.Result = citiesArray to return all rows.
End Sub
End Class
Comentarios
De forma predeterminada, el LinqDataSource control aplica sus expresiones de consulta al objeto definido en la TableName propiedad.By default, the LinqDataSource control applies its query expressions to the object defined in the TableName property. En un controlador para el Selecting evento, puede cambiar manualmente el objeto que se consulta estableciendo la Result propiedad en un objeto.In a handler for the Selecting event, you can manually change which object is queried by setting the Result property to an object. Por ejemplo, puede utilizar la Result propiedad para consultar una colección en memoria en la página web o para obtener los resultados de una expresión de consulta LINQ.For example, you can use the Result property to query an in-memory collection in the Web page, or to get the results from a LINQ query expression. Puede establecer la Result propiedad en cualquier objeto.You can set the Result property to any object. Si el objeto no implementa la IEnumerable<T> interfaz, el LinqDataSource control ajusta el objeto en un objeto que implementa la IEnumerable<T> interfaz.If the object does not implement the IEnumerable<T> interface, the LinqDataSource control wraps the object in an object that does implement the IEnumerable<T> interface.
Cuando la Result propiedad se establece en cualquier valor distinto de null
, el LinqDataSource control no consulta el objeto definido en la TableName propiedad.When the Result property is set to any value other than null
, the LinqDataSource control does not query the object defined in the TableName property. En su lugar, consulta el objeto en la Result propiedad.Instead, it queries the object in the Result property.
Nota
Cuando establezca la Result propiedad en un objeto, no use null
para representar un objeto que no contenga ningún dato.When you set the Result property to an object, do not use null
to represent an object that does not contain any data. El LinqDataSource control se interpreta null
para indicar que la Result propiedad no está establecida y creará y consultará el objeto en la TableName propiedad.The LinqDataSource control interprets null
to mean that the Result property is not set, and it will create and query the object in the TableName property. Para representar un objeto que no contiene datos, establezca la Result propiedad en un IList objeto o IList<T> que no contenga elementos.To represent an object that does not contain data, set the Result property to an IList or IList<T> object that does not contain any elements.
Los ContextCreating ContextCreated eventos, y ContextDisposing no se generan cuando se establece mediante programación la Result propiedad en un objeto y cuando se aplican dos condiciones adicionales.The ContextCreating, ContextCreated, and ContextDisposing events are not raised when you programmatically set the Result property to an object, and when two additional conditions apply. Las condiciones son que los valores originales no tienen que almacenarse en el estado de vista, o bien el objeto de la Result propiedad implementa la ITable interfaz.The conditions are that either the original values do not have to be stored in view state, or the object in the Result property implements the ITable interface.