This project is read-only.
Example #03: One single query to count and list data

1. Here we can send our view to the client, no need to pass any data yet.
public ActionResult OneQueryToCountAndList()
    return View();
2. And then send the data through ajax requests.
[ApplyTransaction, GridAction(EnableCustomBinding = true)]
public ActionResult OneQueryToCountAndListData(GridCommand command)
    // The same query will be used to count and list.
    // WARN: careful with Select N+1 (I purposely left the problem in this query):
    var query = NHibernateHelper.CurrentSession.Query<Product>();
    //// ".Fetch(x => x.Category)" Cant be used here because of an issue in NHibernate: 
    // (currently fixed in the unreleased version 3.3.0)

    var gridHelper = new GridCustomBindingHelper<Product, ProductModel>(command, query);
    var gridModel = gridHelper.BuildGridModel();

    return View(gridModel);
3. Finaly, the Grid configuration
        .Columns(columns =>
            columns.Bound(d => d.ProductID).Width(80);
            columns.Bound(d => d.ProductName);
            columns.Bound(d => d.QuantityPerUnit);
            columns.Bound(d => d.Category.CategoryName).Title("Category");
        .Pageable(x => x.PageSize(15))
        .DataBinding(dataBinding => dataBinding.Ajax()
            .Select<ExamplesController>(ctr => ctr.OneQueryToCountAndListData(null))))

Last edited Feb 28, 2012 at 12:12 AM by Luis_Fernando, version 2


No comments yet.