Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bound columns require a field or property access expression in ASP.NET MVC

I have relations one to many in DB ( i used entity interface to generate associations between 2 obj) Im getting error: Bound columns require a field or property access expression

My code:

in view:

  Html.Telerik()
        .Grid<Y.Orders.Models.Orders>("orders")

        .Name("Orders")
        .DataKeys(dataKeys => dataKeys.Add(o => o.Id))
        //.Pageable(paging => paging.PageSize(20).Style(GridPagerStyles.PageSizeDropDown | GridPagerStyles.NextPreviousAndNumeric))
        .Columns(columns =>
        {
            columns.Command(commands =>
            {
                commands.Custom("comments").ButtonType(GridButtonType.Text).Text("Szczegóły").Action("Index", "Komentarze");
            });
            columns.Bound(o => o.Tytul).Title("Title");
            columns.Bound(o => o.Deliveries.Sum(m=>m.deliveryTime)).Title("Time of order");
        })
        .Filterable()
        .Sortable(sort =>
        {
            sort.SortMode(GridSortMode.MultipleColumn); sort.OrderBy(ord =>
            {
                ord.Add(o => o.Time).Descending();

            });
        })
        .Groupable(grouping => grouping.Groups(groups =>
        {
            groups.Add(c => c.Users.Firms.Name);
        }))
        .Render();

in entity model:

    public ObjectSet<Deliveries>  Deliveries
    {
        get
        {
            if ((_ Deliveries
 == null))
                {
                    _Deliveries = base.CreateObjectSet<Deliveries>("Deliveries");
                }
                return _Deliveries;
            }
        }
        private ObjectSet<Deliveries> _Deliveries;

In deliveries i havnt any null.

Where is problem ?

like image 500
blad1234 Avatar asked Sep 28 '14 17:09

blad1234


1 Answers

columns.Bound accept only primitive as int or string. You can't aggregate or transform object as your example :

o.Deliveries.Sum(m=>m.deliveryTime)

You do create in Deliveries object a parameter as this :

public int SumDeliveries 
{
  get { return this.Sum(m=>m.deliveryTime); }
}

and so you can bind this on grid.

like image 133
User.Anonymous Avatar answered Nov 16 '22 16:11

User.Anonymous