This question is locked. New answers and comments are not allowed.
Hello,
I have probliem with Telerik MVC grid and aggregate functions on ajax binding.
My view :
@{Html.Telerik().Grid<ReportGridVM>() .Name("reportss") .NoRecordsTemplate("Žádné výkazy k dispozici") .Localizable("cs-CZ") .DataBinding(b => b.Ajax() .Select("ReportGrid", "EmployeeReport") ) .DataKeys(c => c.Add(k => k.ReportId)) .Columns(c => { c.Bound(b => b.Created).Format("{0:d}").Title("Vytvořen"); c.Bound(b => b.Contract).Title("Zakázka"); c.Bound(b => b.Service).Title("Služba"); c.Bound(b => b.Comment).Title("Poznámka"); c.Bound(b => b.Hours).Title("Počet hodin").Aggregate(a => a.Sum()).ClientFooterTemplate("Celkem: <strong><#= Sum #>h</strong>"); c.Bound(b => b.ReportId) .Format(Html.ActionLink("Upravit", "EditReport", "EmployeeReport", new { reportId = "{0}" }, new { @class = "t-button" }).ToString()) .Encoded(false) .Filterable(false) .Title("Upravit") .Sortable(false) .Width(60); c.Bound(b => b.ReportId) .Format(Html.ActionLink("Smazat", "DeleteReport", "EmployeeReport", new { reportId = "{0}" }, new { onclick = "return confirm('Opravdu si přejete smazat výkaz');", @class = "t-button" }).ToString()) .Encoded(false) .Filterable(false) .Title("Smazat") .Sortable(false) .Width(60); }) .Sortable() .Selectable() .Pageable() .Render(); }
My controller :
[GridAction] public ActionResult ReportGrid() { var data = from o in _unitOfWork.EmployeeReports.Include(i => i.Employee).Include(i => i.Service).Include(i => i.Contract) select new ReportGridVM { ReportId = o.EmployeeReportId, Comment = o.Comment, Contract = o.Contract.Name, Service = o.Service.Name, Created = o.Created, Hours = o.Hours }; return View(new GridModel { Data = data}); }
When i run example i get Exception :
Unable to cast the type 'System.Int32' to type 'System.Object'. LINQ to Entities only supports casting Entity Data Model primitive type
Where is the problem?
Thanks Martin