Back to Devexpress

ObjectDataSource.DataSource Property

corelibraries-devexpress-dot-dataaccess-dot-objectbinding-dot-objectdatasource-28533370.md

latest7.4 KB
Original Source

ObjectDataSource.DataSource Property

Specifies the object data source that can be a specific object instance or a type.

Namespace : DevExpress.DataAccess.ObjectBinding

Assembly : DevExpress.DataAccess.v25.2.dll

NuGet Package : DevExpress.DataAccess

Declaration

csharp
public object DataSource { get; set; }
vb
Public Property DataSource As Object

Property Value

TypeDescription
Object

A Object value, specifying the data source.

|

Remarks

Because the Data Source wizard cannot be used for binding to a specific object instance, it is required to assign this instance to the DataSource property in code before calling the ObjectDataSource.Fill method. In the wizard, this scenario corresponds to the “Retrieve the data source schema” option.

If the DataSource property has been assigned a type, the ObjectDataSource will try to create an instance of this type when calling the ObjectDataSource.Fill method (this will require specifying the ObjectDataSource.Parameters property). In the wizard, this scenario corresponds to the “Retrieve the actual data” option.

If the ObjectDataSource.DataMember property has been assigned a static member, creating an instance of the corresponding type is not required, nor is specifying the constructor parameters.

The following code snippets (auto-collected from DevExpress Examples) contain references to the DataSource property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

data-access-library-create-data-sources-at-runtime/CS/ObjectDataSourceSnippets/Code.cs#L18

csharp
objds.DataMember = "Items";
objds.DataSource = typeof(BusinessObject);
objds.EndUpdate();

reporting-asp-net-core-inject-data-from-efcore-dbcontext-into-report-using-object-data-source/CS/xrefcoredemo/Services/ObjectDataSourceInjector.cs#L25

csharp
foreach (var ods in DataSourceManager.GetDataSources<ObjectDataSource>(report, includeSubReports: true)) {
    if (ods.DataSource is Type dataSourceType) {
        ods.DataSource = ServiceProvider.GetRequiredService(dataSourceType);

reporting-web-forms-report-designer-add-data-sources/CS/WebApplication1/Default.aspx.cs#L87

csharp
objds.Name = "CustomObjectDataSource";
objds.DataSource = typeof(ItemList);
objds.Constructor = new DevExpress.DataAccess.ObjectBinding.ObjectConstructorInfo();

winforms-dashboard-data-federation/CS/DataFederationExample/Form1.cs#L157

csharp
DashboardObjectDataSource objectDataSource = new DashboardObjectDataSource("Object Data Source");
objectDataSource.DataSource = DataGenerator.Data;
objectDataSource.Fill();

winforms-dashboard-bind-chart-item-to-data-in-code/CS/Dashboard_CreateChart/Form1.cs#L44

csharp
DashboardObjectDataSource dataSource = new DashboardObjectDataSource();
dataSource.DataSource = (new nwindDataSetTableAdapters.SalesPersonTableAdapter()).GetData();
dashboardViewer1.Dashboard.DataSources.Add(dataSource);

data-access-library-create-data-sources-at-runtime/VB/ObjectDataSourceSnippets/Code.vb#L15

vb
objds.DataMember = "Items"
objds.DataSource = GetType(BusinessObject)
objds.EndUpdate()

reporting-web-forms-report-designer-add-data-sources/VB/WebApplication1/Default.aspx.vb#L78

vb
objds.Name = "CustomObjectDataSource"
objds.DataSource = GetType(ItemList)
objds.Constructor = New DevExpress.DataAccess.ObjectBinding.ObjectConstructorInfo()

winforms-dashboard-data-federation/VB/DataFederationExample/Form1.vb#L146

vb
Dim objectDataSource As New DashboardObjectDataSource("Object Data Source")
objectDataSource.DataSource = DataGenerator.Data
objectDataSource.Fill()

winforms-dashboard-bind-chart-item-to-data-in-code/VB/Dashboard_CreateChart/Form1.vb#L46

vb
Dim dataSource As New DashboardObjectDataSource()
dataSource.DataSource = (New nwindDataSetTableAdapters.SalesPersonTableAdapter()).GetData()
dashboardViewer1.Dashboard.DataSources.Add(dataSource)

reporting-wpf-mvvm-viewmodel-data-to-report/VB/EmployeeReport.vb#L17

vb
Me.New()
    objectDataSource1.DataSource = dataSource
End Sub

See Also

ObjectDataSource Class

ObjectDataSource Members

DevExpress.DataAccess.ObjectBinding Namespace