Back to Devexpress

ObjectDataSource.RebuildResultSchema(IEnumerable<IParameter>) Method

corelibraries-devexpress-dot-dataaccess-dot-objectbinding-dot-objectdatasource-dot-rebuildresultschema-x28-system-dot-collections-dot-generic-dot-ienumerable-devexpress-dot-data-dot-iparameter-x29.md

latest6.3 KB
Original Source

ObjectDataSource.RebuildResultSchema(IEnumerable<IParameter>) Method

Rebuilds the ObjectDataSource schema with a data member parameter value.

Namespace : DevExpress.DataAccess.ObjectBinding

Assembly : DevExpress.DataAccess.v25.2.dll

NuGet Package : DevExpress.DataAccess

Declaration

csharp
public void RebuildResultSchema(
    IEnumerable<IParameter> parameters
)
vb
Public Sub RebuildResultSchema(
    parameters As IEnumerable(Of IParameter)
)

Parameters

NameTypeDescription
parametersIEnumerable<IParameter>

A constructor parameter value.

|

Remarks

Call this method to build the data source schema. You can use the schema to bind controls to data source fields.

Pass a collection of external parameters in the RebuildResultSchema(IEnumerable<IParameter>) method call (for instance, report parameters) to apply their values to the data source parameters before the schema is built.

Use the RebuildResultSchema() method instead if you don’t need to pass parameter values.

Example

The code sample below configures an object data source and calls the RebuildResultSchema method with a collection of external parameters to build the data source schema.

csharp
using System.Collections.Generic;
using DevExpress.DataAccess;
using DevExpress.DataAccess.ObjectBinding;
// ...
public class Employee {
    public string Name { get; set; }
    public string Position { get; set; }
}
// The class that fetches data to the ObjectDataSource.
public static class EmployeeDataSource {
    public static IEnumerable<Employee> GetEmployeeList(bool fetchData) {
        if (!fetchData)
            return null;
        var employees = new List<Employee>() {
                new Employee() {
                    Name = "Andrew Fuller",
                    Position = "Vice President, Sales"
                },
                new Employee() {
                    Name = "Nancy Davolio",
                    Position = "Sales Representative"
                },
                new Employee() {
                    Name = "Maria Anders",
                    Position = "Sales Representative"
                },
                new Employee() {
                    Name = "Ana Trujillo",
                    Position = "Owner"
                },
                new Employee() {
                    Name = "Antonio Moreno",
                    Position = "Sales Representative"
                },
                new Employee() {
                    Name = "Thomas Hardy",
                    Position = "Sales Representative"
                },
                new Employee() {
                    Name = "Christina Berglund",
                    Position = "Order Administrator"
                },
                new Employee() {
                    Name = "Frederique Citeaux",
                    Position = "Marketing Manager"
                },
                new Employee() {
                    Name = "Hanna Moos",
                    Position = "Sales Representative"
                },
            };
        return employees;
    }
}
// ...
// Create an ObjectDataSource instance.
ObjectDataSource dataSource = new ObjectDataSource();
dataSource.Name = "objectDataSource1";
dataSource.DataSource = typeof(EmployeeDataSource);
// Specify the data member.
dataSource.DataMember = "GetEmployeeList";
// Specify the data source parameters.
dataSource.Parameters.Add(new Parameter("fetchData", typeof(bool), new Expression("?fetchDataParameter")));
// Build the data source schema.
dataSource.RebuildResultSchema(new[] { new Parameter("fetchDataParameter", typeof(bool), true) });
vb
Imports System.Collections.Generic
Imports DevExpress.DataAccess
Imports DevExpress.DataAccess.ObjectBinding
' ...
Public Class Employee
    Public Property Name() As String
    Public Property Position() As String
End Class
' The class that fetches data to the ObjectDataSource.
Public NotInheritable Class EmployeeDataSource

    Private Sub New()
    End Sub

    Public Shared Function GetEmployeeList(ByVal fetchData As Boolean) As IEnumerable(Of Employee)
        If Not fetchData Then
            Return Nothing
        End If
        Dim employees = New List(Of Employee)() From {
            New Employee() With {.Name = "Andrew Fuller", .Position = "Vice President, Sales"},
            New Employee() With {.Name = "Nancy Davolio", .Position = "Sales Representative"},
            New Employee() With {.Name = "Maria Anders", .Position = "Sales Representative"},
            New Employee() With {.Name = "Ana Trujillo", .Position = "Owner"},
            New Employee() With {.Name = "Antonio Moreno", .Position = "Sales Representative"},
            New Employee() With {.Name = "Thomas Hardy", .Position = "Sales Representative"},
            New Employee() With {.Name = "Christina Berglund", .Position = "Order Administrator"},
            New Employee() With {.Name = "Frederique Citeaux", .Position = "Marketing Manager"},
            New Employee() With {.Name = "Hanna Moos", .Position = "Sales Representative"}
        }
        Return employees
    End Function
End Class

See Also

ObjectDataSource Class

ObjectDataSource Members

DevExpress.DataAccess.ObjectBinding Namespace