@Html.DevExpress().GridView(settings => {
settings.Name = "grid";
settings.CallbackRouteValues = new { Controller = "EFDatabaseServerMode", Action = "GridViewPartial" };
settings.KeyFieldName = "OrderID";
settings.Columns.Add("OrderID");
settings.Columns.Add("CustomerID");
settings.Columns.Add("ShipName");
settings.Columns.Add("ShipAddress");
settings.Settings.ShowGroupPanel = true;
}).BindToEF(string.Empty, string.Empty, (s, e) => {
e.KeyExpression = "OrderID";
e.QueryableSource = Model;
}).GetHtml()
and the controller should NOT issue .ToList()
.
public class EFDatabaseServerModeController : Controller {
NorthwindContext db = new NorthwindContext();
public ActionResult Index() {
return View();
}
public ActionResult GridViewPartial() {
return PartialView(db.Orders);
}
}
Column names with spaces need mapping in the model e.g.
public class NorthwindContext : DbContext {
public NorthwindContext() : base("SQLCompact_Northwind_Connection") { }
public DbSet<Order> Orders { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder) {
modelBuilder.Entity<Order>().Property(p => p.OrderID).HasColumnName("Order ID");
modelBuilder.Entity<Order>().Property(p => p.CustomerID).HasColumnName("Customer ID");
modelBuilder.Entity<Order>().Property(p => p.ShipName).HasColumnName("Ship Name");
modelBuilder.Entity<Order>().Property(p => p.ShipAddress).HasColumnName("Ship Address");
}
}
Note
Enable the GridViewSettings.EnableRowsCache
option to reduce the number of calls to a bound data source when the GridView functions in Database Server Mode. When the GridView extension functions in regular data binding mode, the GridViewSettings.EnableRowsCache should be disabled.
Also note there are limitations with exporting data in server mode...
- See the docs for Binding to large data.
- See the docs for BindToEF.
- There is a sample project here
- Performance suggestions
- ExtensionSuite documentation