开发者

TypeAccessException when sorting using RIA Services and Telerik RadGridView

开发者 https://www.devze.com 2023-04-01 01:25 出处:网络
I\'m using RadGrid in a SL app using RIA services / MVVM In my Viewmodel I have an IEnumerable collection that works fine when simply exposing the collection:

I'm using RadGrid in a SL app using RIA services / MVVM

In my Viewmodel I have an IEnumerable collection that works fine when simply exposing the collection:

public IEnumerable<Orders> OrderList
    {
        get
        {
            return datacontext.Orders;
        }
    }

However, when I try to sort the collection before it's bound (as follows) I get an error "Message: System.typeaccessexception Attempt by method DynamicClass.lambda ..... " and the application hangs:

public IEnumerable<Orders> OrderList
    {
        get
        {
            return  datacontext.Orders.OrderBy(o=>o.OrderDate);
        }
    }

Can you advise how to 开发者_如何转开发expose the data sorted without causing this issue?


You can add .ToArray() or .ToList() call to the end of your LINQ query, for example:

public IEnumerable<Orders> OrderList
    {
        get
        {
            return  datacontext.Orders.OrderBy(o=>o.OrderDate).ToList();
        }
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号