DashboardEFDataSource Class
An Entity Framework data source that provides data for the dashboard.
Namespace: DevExpress.DashboardCommon
Assembly: DevExpress.Dashboard.v18.2.Core.dll
Declaration
public class DashboardEFDataSource :
EFDataSource,
IDashboardDataSource,
IDashboardComponent,
IComponent,
IDisposable,
ISupportInitialize,
ISupportPrefix,
IDashboardDataSourceInternal,
IExternalSchemaConsumer
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.
- 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
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.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-bind-a-dashboard-to-an-entity-framework-data-source-at-runtime-t213415.
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