Skip to main content
All docs
V24.2

Use EFDataSource

  • 2 minutes to read

EFDataSource is a data component that binds to Entity Framework Data Models, including stored procedures.

When you create the EFDataSource component, you should specify its ConnectionParameters property. The property value is the EFConnectionParameters object, which has different constructors to ensure flexibility during runtime instantiation. The following code snippet creates the EFDataSource component at runtime:

public static class EFConnectionParams  
{  
    public static string Connection {  
        get {  
            return "Data Source=localhost;Initial Catalog=Northwind;Persist Security Info=True;User ID=sa;Password=pwd;MultipleActiveResultSets=True;Application Name=EntityFramework";  
        }  
    }  
    public static Type SourceType { get { return typeof(NorthwindEntities); } }  
}  
...  
DevExpress.DataAccess.EntityFramework.EFDataSource efds = new DevExpress.DataAccess.EntityFramework.EFDataSource();  
GenerateEFDataSource(efds);  
...  
private void GenerateEFDataSource(DevExpress.DataAccess.EntityFramework.EFDataSource efds) {  
    ((System.ComponentModel.ISupportInitialize)(efds)).BeginInit();  
    efds.Name = "efDataSource1";  
    efds.ConnectionParameters = ConfigureEfConnectionParameters();  
    efds.StoredProcedures.Add(GetStoredProcedure());  
    ((System.ComponentModel.ISupportInitialize)(efds)).EndInit();  
}  
private DevExpress.DataAccess.EntityFramework.EFConnectionParameters ConfigureEfConnectionParameters() {  
    DevExpress.DataAccess.EntityFramework.EFConnectionParameters efConnParam = new DevExpress.DataAccess.EntityFramework.EFConnectionParameters();  
    efConnParam.ConnectionString = EFConnectionParams.Connection;  
    efConnParam.ConnectionStringName = "";  
    efConnParam.Source = EFConnectionParams.SourceType;  
    return efConnParam;  
}  
private DevExpress.DataAccess.EntityFramework.EFStoredProcedureInfo GetStoredProcedure() {  
    DevExpress.DataAccess.EntityFramework.EFStoredProcedureInfo efStoredProcedureInfo1 = new DevExpress.DataAccess.EntityFramework.EFStoredProcedureInfo();  
    efStoredProcedureInfo1.Name = "CustOrderHist";  
    DevExpress.DataAccess.EntityFramework.EFParameter efParameter1 = new DevExpress.DataAccess.EntityFramework.EFParameter();  
    efParameter1.Name = "CustomerID";  
    efParameter1.Type = typeof(string);  
    efParameter1.ValueInfo = "ALFKI";  
    efStoredProcedureInfo1.Parameters.Add(efParameter1);  
    return efStoredProcedureInfo1;  
}  

All queries and stored procedures should be available at the Entity Framework Data Model level. The EFDataSource operates with the already created Data Model specified with the EFConnectionParameters.Source property. Unlike the SqlDataSourcer, the EFDataSource cannot generate queries and stored procedures dynamically.