Accepted answer

if that is one method call, it wont work. silverlight calls are asynchronous you have to provide a callback for the load method so that when its done it dumps to a new method....

private readonly tamplatetablecontext m_tablecontext = new tamplatetablecontext();


public void onloadoperationcompleted(loadoperation<templatetable> lo)
            if (!lo.haserror)
               lbtemplatetable.datacontext = 
                  new observablecollection<templatetable>(lo.entities.orderby(a =>;

its a contrived example. i use mvvmlight and a servicelocator pattern, so what i am showing you isnt really in context because it looks like you may actually be doing it all in code behind...but i was really just trying to show you how to do the callback.


you cannot inspect lambda expressions at runtime. they need to be compiled, even changing a method containing a lambda (not just the lambda itself) at runtime requires recompilation.


it's a bit hard to tell by the current code. example below uses the same orderby expression, and it compiles and runs ok.

public class a { public int id; }

public static void test()
    list<a> lista = new list<a> {new a {id=7}, new a {id=2}, new a {id=16}};

    var query1 = from x in lista orderby select x;
    var query2 = (from x in lista select x).orderby(a =>;

    foreach(var x1 in query1) console.writeline("{0}",;
    foreach(var x2 in query2) console.writeline("{0}",;

error you have might actually come from insufficient information about key data type. this discussion might help you with it.

update: ah, it's in debug, as in debug mode, not debug target, is it ?!... if you are trying to see the result in quick watch or immediate window - it's expected error. this doesn't mean that there is something wrong with the code, just that debugger doesn't like lambda expressions.

Related Query

More Query from same tag