Example #08: Direct usage of a TEntity (without TEntity to TViewModel mappings)

1. Here we can send our view to the client, no need to pass any data yet.
public ActionResult DirectUsageOfTEntity()
{
    return View();
}
2.1. Generic Linq version:
[ApplyTransaction, GridAction(EnableCustomBinding = true)]
public ActionResult DirectUsageOfTEntityData(GridCommand command)
{
    var query = NHibernateHelper.CurrentSession.Query<Supplier>();

    var gridHelper = new GridEntityCustomBindingHelper<Supplier>(command, query);

    var gridModel = gridHelper.BuildGridModel();

    return View(gridModel);
}
2.2. NHibernate QueryOver API version:
[ApplyTransaction, GridAction(EnableCustomBinding = true)]
public ActionResult DirectUsageOfTEntityNHibernateData(GridCommand command)
{
    var query = NHibernateHelper.CurrentSession.QueryOver<Supplier>();

    var gridHelper =
        new NHibernateGridEntityCustomBindingHelper<Supplier>(command, query);

    var gridModel = gridHelper.BuildGridModel();

    return View(gridModel);
}
3. Finaly, the Grid configuration
@(Html.Telerik().Grid<Supplier>().Name("Grid")
        .Columns(columns =>
        {
            columns.Bound(d => d.SupplierID).Width(80);
            columns.Bound(d => d.ContactName);
            columns.Bound(d => d.ContactTitle);
            columns.Bound(d => d.Address);
            columns.Bound(d => d.City);
            columns.Bound(d => d.PostalCode);
            columns.Bound(d => d.Country);
        })
        .EnableCustomBinding(true).Sortable().Filterable().Groupable()
        .Pageable(x => x.PageSize(15))
        .DataBinding(dataBinding => dataBinding.Ajax()
            .Select<ExamplesController>(ctr => ctr.DirectUsageOfTEntityData(null))))

Last edited Feb 27, 2012 at 11:15 PM by Luis_Fernando, version 3

Comments

No comments yet.