dashboard-devexpress-dot-dashboardcommon-e3c7b823.md
An Entity Framework data source that provides data for the dashboard.
Namespace : DevExpress.DashboardCommon
Assembly : DevExpress.Dashboard.v25.2.Core.dll
NuGet Package : DevExpress.Dashboard.Core
public class DashboardEFDataSource :
EFDataSource,
IDashboardDataSource,
IDashboardComponent,
IComponent,
IDisposable,
ISupportInitialize,
ISupportPrefix,
IDashboardDataSourceInternal,
IExternalSchemaConsumer,
IFederationDataProvider
Public Class DashboardEFDataSource
Inherits EFDataSource
Implements IDashboardDataSource,
IDashboardComponent,
IComponent,
IDisposable,
ISupportInitialize,
ISupportPrefix,
IDashboardDataSourceInternal,
IExternalSchemaConsumer,
IFederationDataProvider
DashboardEFDataSource supports the following Entity Framework versions:
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.
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.
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; }
}
}
Imports System.Data.Entity
Imports System
Namespace Dashboard_EntityFramework
Partial Public Class OrdersContext
Inherits DbContext
Public Sub New()
MyBase.New("name=OrdersContext")
End Sub
Public Overridable Property Orders() As DbSet(Of Order)
End Class
Partial Public Class Order
Public Property OrderID() As Long
Public Property CustomerID() As String
Public Property EmployeeID() As Long?
Public Property OrderDate() As Date?
Public Property RequiredDate() As Date?
Public Property ShippedDate() As Date?
Public Property ShipVia() As Long?
Public Property Freight() As Decimal?
Public Property ShipName() As String
Public Property ShipAddress() As String
Public Property ShipCity() As String
Public Property ShipRegion() As String
Public Property ShipPostalCode() As String
Public Property ShipCountry() As String
End Class
End Namespace
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;
}
}
}
Imports DevExpress.DashboardCommon
Imports DevExpress.XtraEditors
Imports DevExpress.DataAccess.EntityFramework
Namespace Dashboard_EntityFramework
Partial Public Class Form1
Inherits XtraForm
Public Sub New()
InitializeComponent()
InitializeDashboard()
End Sub
Public Sub InitializeDashboard()
Dim dashboard As New Dashboard()
Dim efDataSource As New DashboardEFDataSource()
efDataSource.ConnectionParameters = New EFConnectionParameters(GetType(OrdersContext))
dashboard.DataSources.Add(efDataSource)
Dim pivot As 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"))
Dim chart As New ChartDashboardItem()
chart.DataSource = dashboard.DataSources(0)
chart.DataMember = "Orders"
chart.Arguments.Add(New Dimension("OrderDate", DateTimeGroupInterval.Year))
chart.Panes.Add(New ChartPane())
Dim freightSeries As New SimpleSeries(SimpleSeriesType.Bar)
freightSeries.Value = New Measure("Freight")
chart.Panes(0).Series.Add(freightSeries)
dashboard.Items.AddRange(pivot, chart)
dashboardViewer1.Dashboard = dashboard
End Sub
End Class
End Namespace
Object MarshalByRefObject Component DataComponentBase EFDataSource DashboardEFDataSource
See Also