DashboardEFDataSource Class

An Entity Framework data source that provides data for the dashboard.

Namespace: DevExpress.DashboardCommon

Assembly: DevExpress.Dashboard.v21.2.Core.dll

Declaration

public class DashboardEFDataSource :
    EFDataSource,
    IDashboardDataSource,
    IDashboardComponent,
    IComponent,
    IDisposable,
    ISupportInitialize,
    ISupportPrefix,
    IDashboardDataSourceInternal,
    IExternalSchemaConsumer,
    IFederationDataProvider

Remarks

Depending on whether the Entity Framework model is added to the current project or is contained in an external assembly, you can create the DashboardEFDataSource data source in two ways.

Use the EFDataSource.Fill method to retrieve data from the data source.

Note

DashboardEFDataSource supports the following Entity Framework versions:

  • Entity Framework 5.0 and higher.
  • Entity Framework Core 1.0 and higher.

Note that the Entity Framework context class passed to an EFConnectionParameters.Source should be public.

Note

To connect to different database types using DashboardEFDataSource, you need to install a corresponding data provider. For instance, install the System.Data.SQLite.EF6 data provider to connect to an SQLite database using Entity Framework 6.

Example

The following example demonstrates how to bind a dashboard to the SQLite database using Entity Framework 6.

In this example, the DashboardEFDataSource class is used to connect the dashboard to the Entity Framework data source.

View Example

namespace Dashboard_EntityFramework {
    using System;
    using System.Data.Entity;

    public partial class OrdersContext : DbContext {
        public OrdersContext()
            : base("name=OrdersContext") {
        }
        public virtual DbSet<Order> Orders { get; set; }
    }

    public partial class Order {
        public long OrderID { get; set; }
        public string CustomerID { get; set; }
        public long? EmployeeID { get; set; }
        public DateTime? OrderDate { get; set; }
        public DateTime? RequiredDate { get; set; }
        public DateTime? ShippedDate { get; set; }
        public long? ShipVia { get; set; }
        public decimal? Freight { get; set; }
        public string ShipName { get; set; }
        public string ShipAddress { get; set; }
        public string ShipCity { get; set; }
        public string ShipRegion { get; set; }
        public string ShipPostalCode { get; set; }
        public string ShipCountry { get; set; }
    }
}
using DevExpress.DashboardCommon;
using DevExpress.XtraEditors;
using DevExpress.DataAccess.EntityFramework;

namespace Dashboard_EntityFramework {
    public partial class Form1 : XtraForm {
        public Form1() {
            InitializeComponent();
            InitializeDashboard();          
        }

        public void InitializeDashboard() {
            Dashboard dashboard = new Dashboard();
            DashboardEFDataSource efDataSource = new DashboardEFDataSource();
            efDataSource.ConnectionParameters =
                new EFConnectionParameters(typeof(OrdersContext));
            dashboard.DataSources.Add(efDataSource);

            PivotDashboardItem pivot = new PivotDashboardItem();
            pivot.DataMember = "Orders";
            pivot.DataSource = dashboard.DataSources[0];
            pivot.Rows.AddRange(new Dimension("ShipCountry"), new Dimension("ShipCity"));
            pivot.Columns.Add(new Dimension("OrderDate"));
            pivot.Values.Add(new Measure("Freight"));

            ChartDashboardItem chart = new ChartDashboardItem();
            chart.DataSource = dashboard.DataSources[0];
            chart.DataMember = "Orders";
            chart.Arguments.Add(new Dimension("OrderDate", DateTimeGroupInterval.Year));
            chart.Panes.Add(new ChartPane());
            SimpleSeries freightSeries = new SimpleSeries(SimpleSeriesType.Bar);
            freightSeries.Value = new Measure("Freight");
            chart.Panes[0].Series.Add(freightSeries);

            dashboard.Items.AddRange(pivot, chart);
            dashboardViewer1.Dashboard = dashboard;
        }
    }
}

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

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.

See Also