Skip to content

Instantly share code, notes, and snippets.

@shamp00
Last active September 1, 2016 10:58
Show Gist options
  • Save shamp00/57fc1faae3a1843bee2f00149e5de4cc to your computer and use it in GitHub Desktop.
Save shamp00/57fc1faae3a1843bee2f00149e5de4cc to your computer and use it in GitHub Desktop.
Notes on MVC GridExtension in server mode

Server mode EF binding example

@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);
        }
    }

Mapping

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");
        }
    }

Consider

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...

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment