score:0
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();
m_tablecontext.load(m_tablecontext.gettemplatetablequery(),onloadoperationcompleted);
public void onloadoperationcompleted(loadoperation<templatetable> lo)
{
if (!lo.haserror)
{
lbtemplatetable.datacontext =
new observablecollection<templatetable>(lo.entities.orderby(a => a.id));
}
}
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.
score:1
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.
score:2
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 x.id select x;
var query2 = (from x in lista select x).orderby(a => a.id);
foreach(var x1 in query1) console.writeline("{0}", x1.id);
foreach(var x2 in query2) console.writeline("{0}", x2.id);
}
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.
Source: stackoverflow.com
Related Query
- linq - how do you do a query for items in one query source that are not in another one?
- How can I write the following code more elegantly using LINQ query syntax?
- How to dynamic add filters to a LINQ query against an Odata Source in C#
- How do I get results from a Linq query in the order of IDs that I provide?
- How to get SQL query into LINQ form in C# code
- How do I simplify a LINQ query with multiple .Select() in order to return an IQueryable(int)
- How can I code a Linq query to do an upward Include?
- LINQ Query - how order by?
- How to order list in custom Item class with linq query
- How can I check the number of calls to the database in LINQ query when using .NET Core and Code First?
- How to Group and Order in a LINQ Query
- How do I determine the source of unpredictable LINQ query results?
- How to Select top (5) contributors group by Business type code in c# linq query
- How can I code numerous MIN functions into one LINQ to DataSet query
- How to code this LINQ query in a better way
- How to write aggregate query in LINQ reusing part of the select code
- How to execute code as a part of the LINQ query
- how to write a Linq query with a EF code first Many to Many relationship
- How to get a Linq query to order results based on the order of arguments in a method signature
- Will Linq query code in C# UWP project work slower or faster depending on order of its' parts?
- How to LINQ Query Code First generated EF6 hierarchical entities (entities within entities)?
- How can I order the output of my long LINQ query by a double and then a string?
- How to sort a loop order using linq query in C#?
- How to Order Data Query in Entity Framework Table Relationships LINQ Method syntax?
- How to set order by descending in Linq query based on aggregated column?
- how to fetch data from database using linq query for relationship 1:N and N:N (between 3 entity) in asp.net mvc EF code first?
- How to assign LINQ Query to a variable and then use it later in the code
- How to set order of IQueryable query based on another list using linq in c#?
- How to use order by clause in linq query with dynamic conditions?
- LINQ query on dotnet code and how concat will work here
More Query from same tag
- Is it possible to group LINQ elements based on a sequence?
- How to avoid if else statements in filter API in Linq
- Updating Telerik Rad Grid?
- C# Linq Combine multiple sequences by key
- many-to-many relationship in mvc and EF
- Using LINQ get the differences between two tables
- Returning two values immediately surrounding a test value in an IEnumerable<float>
- Add xmlns attribute to root element
- Loading 400+ images from SQL via LINQ
- Compare 2 Collections and get Modified items
- linq groupby plus select returning element type rather than value
- What's the point of lambda expression in OrderBy?
- Double join returns duplicate results
- Relatively simple SQL query to Linq (with grouping)
- Can't Insert new record from WPF Datagrid via LINQ-to-SQL
- Query for static type in Linq
- Why does joining two related CSV files by using a join clause produce a single element instead of a sequence of elements?
- How to validate that 4 fields are not repeated in any manner
- Selecting both parent and child items when querying child properties
- Update a value with linq
- c# left join whith several tables
- Is there any elegant way in LINQ to bucket a collection into a set of lists based on a property
- EF - cannot convert from System.Linq.IQueryable to System.Data.Objects.ObjectQuery
- Select EF entities that have all the given Tags (where tag is an EF entity)
- LINQ How to define a default type for use with ElementAtOrDefault Operator
- How do I keep the lastest entry of an item from a database
- strip out tag occurrences from XML
- Problem: Failed to load viewstate
- EntitySet vs Table query performance in LINQ2SQL
- linq query to filter with list<int> condition