This is a migrated thread and some comments may be shown as answers.

Aggregates throw error

2 Answers 54 Views
Grid
This is a migrated thread and some comments may be shown as answers.
faris
Top achievements
Rank 1
faris asked on 02 Aug 2017, 06:20 AM

Im using 3 tier.

1 presenter

2 service (webapi & service business logic layer)

3 data access

this is my presenter code

@(Html.Kendo().Grid<ParkingRevenueViewModel>()
  .Name("grid")
  .Columns(columns =>
  {
      columns.Bound(p => p.ParkDate).Width(20).Title("Date").Format("{0:dd/MM/yyyy}").Filterable(true);
      columns.Bound(p => p.VehRegNbr).Width(100).Title("Vehicle No");
      columns.Bound(p => p.RoadName).Width(150).Title("Road").Filterable(false);
      columns.Bound(p => p.LotNo).Width(50).Title("Lot No");
      columns.Bound(p => p.StartTime).Width(100).Title("Parking Time").Format("{0:dd/MM/yyyy h:mm:ss tt}").Filterable(false);
      columns.Bound(p => p.Value).Width(50).Title("Value").Filterable(false);
  })
  .Filterable()
    .Pageable()
 
    .DataSource(dataSource =>
    dataSource
    .WebApi()
        .Aggregates(aggregates =>
        {
            aggregates.Add(p => p.Value).Sum();
        })
    .Events(events => events.Error("error_handler"))
    ).Deferred()
        )
 

 

this is my webapi code

[HttpGet("ParkingRevenueByMonth")]
        public DataSourceResult ParkingRevenueByMonth([DataSourceRequest]DataSourceRequest request, int? Month = 0)
        {
            var model = reportsService.GetParkingRevenueByMonth(request, Month);
            return model;
        }

 

service layer

public DataSourceResult GetParkingRevenueByMonth(DataSourceRequest request, int? Month=0)
        {
 
            var now = DateTime.Now.ConvertToMalaysiaTime();
            if (Month == null || Month == 0)
            {
                Month = now.Month;
            }
            var firstOfMonth = new DateTime(now.Year, (int)Month, 1);
            var endOfMonth = firstOfMonth.AddMonths(1).AddMilliseconds(-1);
 
            var list = unitOfWork.GetRepository<ParkTable>().GetAll().Where(w=> firstOfMonth.Date <= w.TimeStart.Date && w.TimeStart.Date <= endOfMonth.Date);
            var returnModel = list.Select(s => new ParkingRevenueViewModel
 
            {
                ParkDate = s.TimeStart.Date,
                VehRegNbr = s.VehRegNbr,
                LotNo = s.GeoRoadParkLot.GeoParkLot.LotNo,
                RoadName = s.GeoRoadParkLot.GeoRoad.Description,
                StartTime = s.TimeStart,
                Value = s.Amount
            });
 
            return returnModel.ToDataSourceResult(request);
        }

 

the error thrown

at Kendo.Mvc.Infrastructure.Implementation.Expressions.GroupDescriptorExpressionBuilder.CreateProjectionNewExpression(IEnumerable`1 propertyValuesExpressions)
at Kendo.Mvc.Infrastructure.Implementation.Expressions.GroupDescriptorExpressionBuilder.CreateProjectionInitExpression()
at Kendo.Mvc.Infrastructure.Implementation.Expressions.GroupDescriptorExpressionBuilder.CreateAggregateFunctionsProjectionMemberBinding()
at Kendo.Mvc.Infrastructure.Implementation.Expressions.QueryableAggregatesExpressionBuilder.<CreateMemberBindings>d__3.MoveNext()
at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source, Int32& length)
at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source)
at System.Dynamic.Utils.CollectionExtensions.ToReadOnly[T](IEnumerable`1 enumerable)
at System.Linq.Expressions.Expression.MemberInit(NewExpression newExpression, IEnumerable`1 bindings)
at Kendo.Mvc.Infrastructure.Implementation.Expressions.GroupDescriptorExpressionBuilder.CreateSelectExpression()
at Kendo.Mvc.Infrastructure.Implementation.Expressions.GroupDescriptorExpressionBuilderBase.CreateQuery()
at Kendo.Mvc.Extensions.QueryableExtensions.Aggregate(IQueryable source, IEnumerable`1 aggregateFunctions)
at Kendo.Mvc.Extensions.QueryableExtensions.CreateDataSourceResult[TModel,TResult](IQueryable queryable, DataSourceRequest request, ModelStateDictionary modelState, Func`2 selector)
at Kendo.Mvc.Extensions.QueryableExtensions.ToDataSourceResult(IEnumerable enumerable, DataSourceRequest request)
at NI.Service.ReportsServices.GetParkingRevenueByMonth(DataSourceRequest request, Nullable`1 Month) in d:\documents\visual studio 2017\Projects\Nova\NI.Service\ReportsServices.cs:line 53
at NI.WebApi.Controllers.ReportsController.ParkingRevenueByMonth(DataSourceRequest request, Nullable`1 Month) in d:\documents\visual studio 2017\Projects\Nova\TestApi2\Controllers\ReportsController.cs:line 32
at lambda_method(Closure , Object , Object[] )
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionMethodAsync>d__27.MoveNext()

 

 

 

2 Answers, 1 is accepted

Sort by
0
faris
Top achievements
Rank 1
answered on 03 Aug 2017, 03:47 AM

i try to use url to presenter controller its working. but for webapi url not working.

 

please help me

0
Angel Petrov
Telerik team
answered on 04 Aug 2017, 02:14 PM
Hello,

Could you please elaborate on what version of Kendo is the project using? 

In order to provide a precise answer, in regards of the matter, I suggest opening a formal support ticket and attaching a small sample there. That way we should be able to debug the project and further investigate the matter.

Regards,
Angel Petrov
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
faris
Top achievements
Rank 1
Answers by
faris
Top achievements
Rank 1
Angel Petrov
Telerik team
Share this question
or