开发者

TypeAccessException when sorting using RIA Services and Telerik RadGridView

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜