DashboardEFDataSource Class
An Entity Framework data source that provides data for the dashboard.
Namespace: DevExpress.DashboardCommon
Assembly: DevExpress.Dashboard.v24.1.Core.dll
NuGet Package: DevExpress.Dashboard.Core
Declaration
public class DashboardEFDataSource :
EFDataSource,
IDashboardDataSource,
IDashboardComponent,
IComponent,
IDisposable,
ISupportInitialize,
ISupportPrefix,
IDashboardDataSourceInternal,
IExternalSchemaConsumer,
IFederationDataProvider
Remarks
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.
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.
- If the current project contains the required model, pass the type of the required context to the EFConnectionParameters constructor. Then specify the connection using the EFConnectionParameters.ConnectionString property and assign the resulting EFConnectionParameters object to the EFDataSource.ConnectionParameters property.
- If the required model is contained in an external assembly, pass the context name and the path to the assembly to the EFConnectionParameters constructor. Then specify the connection using the EFConnectionParameters.ConnectionString property and assign the resulting EFConnectionParameters object to the EFDataSource.ConnectionParameters property.
Use the EFDataSource.Fill method to retrieve data from the data source.
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.
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;
}
}
}