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

[Solved] EF 4.2 CodeFirst Descending not working in grid

2 Answers 87 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Dan Miser
Top achievements
Rank 1
Dan Miser asked on 10 Feb 2012, 04:30 AM
     public IQueryable<Collection> Collections
        {
           
get
            {
               
return   
                    from c in context.Collections
                    orderby c.CollectionDate descending
                    select c;
            }
        }

Index.cshtml
@model IQueryable<MyProject.Models.Collection>
<
div>
@{ Html.Telerik().Grid(Model)
    .Name("Grid")
    .PrefixUrlParameters(false)
    .Columns(columns =>
        {
            columns.Add(c => c.Location.Name).Width(160);
            columns.Add(o => o.CollectionDate);
        })
    .Scrollable()
    .Sortable()
    .Pageable()
    .Filterable()
    .Render();
    }
</div>

Using the above code with the Telerik MVC 2011.3.1115 controls, the grid is not respecting the descending order. Looking at the generated query via the EF Profiler, the query is actually tuning into an "ORDER BY ID ASC". If I do a ToList() on the Collections property, the data in the grid is sorted by CollectionDate, but then *all* of the data is returned back in the query which won't be very efficient.

One other dataoint: I ran this same code when I was using Mindscape's Lightspeed ORM, and it sorted fine.

Any thoughts on where things are going wrong?

2 Answers, 1 is accepted

Sort by
0
Dan Miser
Top achievements
Rank 1
answered on 16 Feb 2012, 12:58 AM
Any thoughts? Does this work for anyone else?
0
Dan Miser
Top achievements
Rank 1
answered on 28 Feb 2012, 10:15 PM
This one is still broken with 2012.1.214. Any thoughts on why or what to do to work around it?
Tags
Grid
Asked by
Dan Miser
Top achievements
Rank 1
Answers by
Dan Miser
Top achievements
Rank 1
Share this question
or