Example #04: NHibernate QueryOver API1. Here we can send our view to the client, no need to pass any data yet.
public ActionResult NHibernateQueryOver()
{
return View();
}
2. And then send the data through ajax requests.
[ApplyTransaction, GridAction(EnableCustomBinding = true)]
public ActionResult NHibernateQueryOverData(GridCommand command)
{
// QueryOver API from NHibernate, fetching an association is not a problem here
// Careful with Select N+1: http://nhprof.com/Learn/Alerts/SelectNPlusOne
var query = NHibernateHelper.CurrentSession.QueryOver<Product>()
.Fetch(x => x.Category).Eager;
//var queryToCount = NHibernateHelper.GetCurrentSession().QueryOver<Product>()
.Fetch(x => x.Category).Eager;
var gridHelper =
new NHibernateGridCustomBindingHelper<Product, ProductModel>(command, query);
gridHelper.BuildGridModel();
var gridModel = gridHelper.BuildGridModel();
return View(gridModel);
}
3. Finaly, the Grid configuration
@(Html.Telerik().Grid<ProductModel>().Name("Grid")
.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");
})
.EnableCustomBinding(true).Sortable().Filterable().Groupable()
.Pageable(x => x.PageSize(15))
.DataBinding(dataBinding => dataBinding.Ajax()
.Select<ExamplesController>(ctr => ctr.NHibernateQueryOverData(null))))