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

[Solved] Grid Columns, LINQ Error

3 Answers 88 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.
Stefan
Top achievements
Rank 1
Stefan asked on 08 Jul 2010, 02:00 PM
Hi there,

I've the following classes - using Entity Framework 4.

* Partner
   - Name
   - Email
   - ...
   - Address (following Class)

* Address
   - Street
   - City
   - ...
   - Country (following Class)

* Country
   - Name
   - Currency
   - ...

A Partner can have multiple Addresses, an Address can only have one Country.

Now I want to display the following properties:

Partner.Name
Partner.Address.Street
Partner.Address.City
Partner.Address.Country.Name

It works perfectly fine except for displaying Partner.Address.Country.Name. I always get the following exception:

"Unable to cast object of type 'System.Linq.Expressions.MethodCallExpressionN' to type 'System.Linq.Expressions.ParameterExpression'."

If I try to output Partner.Address.Country, I get the property names and values as an output. I also see the "Name" property with my intellisense. It just doesn't run through the output.

That's my code:

<%= Html.Telerik().Grid(Partner)
            .Name("Grid")
            .Columns(columns =>
            {
                columns.Bound(i => i.Name);
                columns.Bound(i => i.Addresses.ToList().First().Street);
                columns.Bound(i => i.Addresses.ToList().First().Country.Name);
                columns.Bound(i => i.Website).Width(100);
            })
            .Sortable()
            .Pageable()
            .Footer(true)
    %>

Any ideas? Thanks in advance.

3 Answers, 1 is accepted

Sort by
0
Wai Kei
Top achievements
Rank 1
answered on 05 Oct 2010, 04:04 PM
I have the same problem? Who could help?
0
Matt Andreko
Top achievements
Rank 1
answered on 27 Oct 2010, 07:11 PM
I'm unfortunately also seeing this issue, although not with EF4.  My code looks like this:

<%
Html.Telerik()
.Grid((IEnumerable<OpportunityModel>)ViewData["SalesOpportunities"])
.Name("SalesOpportunities")
.Columns(cols =>
            {
                 cols.Bound(c => c.VehiclesOfInterest.First(v => v.IsPrimaryVehicleOfInterest).ConcreteVehicle.StockNumber);
                 cols.Bound(c => c.OpenDate);
                 cols.Bound(c => c.Status);
            }).Render();
%>

 It apparently doesn't like the first column.  If I comment it out, and show just the simply bound columns, it looks fine.  
0
Matt Andreko
Top achievements
Rank 1
answered on 27 Oct 2010, 08:01 PM
As a workaround, I found that using a template column like this works:

<%
Html.Telerik()
.Grid((IEnumerable<OpportunityModel>)ViewData["SalesOpportunities"])
.Name("SalesOpportunities")
.Columns(cols =>
         {
 
             cols.Template(c =>
                           {
                           %>
                                <%= c.VehiclesOfInterest.First(v => v.IsPrimaryVehicleOfInterest).ConcreatVehicle.StockNumber %>
                           <%
                           });
             cols.Bound(c => c.OpenDate);
             cols.Bound(c => c.Status);
              
            }).Render();
%>
Tags
General Discussions
Asked by
Stefan
Top achievements
Rank 1
Answers by
Wai Kei
Top achievements
Rank 1
Matt Andreko
Top achievements
Rank 1
Share this question
or