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

[Solved] Telerik mvc grid and entity framework 4.1 linq provider

3 Answers 196 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Martin Sura
Top achievements
Rank 1
Martin Sura asked on 05 Jun 2011, 09:09 PM

 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

3 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 06 Jun 2011, 08:13 AM
Hi Martin Sura,

 We cannot reproduce the problem locally. Probably it is something specific to your model. Could you send a sample project which demonstrates this behavior?

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Martin Sura
Top achievements
Rank 1
answered on 06 Jun 2011, 10:07 AM

Hello,

Thanks for reply.

In attachment I send simple asp.net mvc project with db structure and grid.

Martin

0
Accepted
Rosen
Telerik team
answered on 06 Jun 2011, 04:13 PM
Hi Martin Sura,

Thank you for the additional details. The described issue is a known issue which have been already resolved with Q1 SP1 2011 release.

All the best,
Rosen
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
Martin Sura
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Martin Sura
Top achievements
Rank 1
Rosen
Telerik team
Share this question
or