Home » .Net FrameworkRSS

OData for Windows Phone 7 Problems with LinQ Queries

Hi, I posted some thread on the WP7 forum before I found this forum. Maybe here I could get more help.

See the original thread: http://social.msdn.microsoft.com/Forums/en-US/windowsphone7series/thread/62a6b89c-584a-42ac-ba85-ecec0a6f186b

I managed to get the proxy classes generated.

Data retrieval works if I just retrieve the complete collection.

If I ever try to filter data via a LinQ query in the LoadAsync script, I will be doomed. Exception.

For example:

var query from a in data.Entity where a.Name="Hello" select a;
data.LoadAsync(query);
works. Seems like a String constant makes no problem.

String param="Hello" param given as a function parameter to the following line:
var query from a in data.Entity where a.Name=param select a;
data.LoadAsync(query);
crashes.

More complex queries will not work either - I try for example to get a match for a DateTime but no way...

Here is the dump the debugger gives me:

Expression:[10000].Select(o => o)
Expression2:[10000].Where(o => (o.Mahlzeit = value(MyDietLogWP7.ModelHandler+<>c__DisplayClass0).mahlzeit))
A first chance exception of type 'System.MethodAccessException' occurred in mscorlib.dll
A first chance exception of type 'System.MethodAccessException' occurred in System.Data.Services.Client.dll
Error:System.MethodAccessException: MethodAccessException
 at System.Reflection.RuntimeConstructorInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)
 at System.Activator.InternalCreateInstance(Type type, BindingFlags invokeAttr, Binder binder, Object[] args, CultureInfo culture, StackCrawlMark& stackMark)
 at System.Activator.CreateInstance(Type type, Object[] args)
 at IQToolkit.ExpressionEvaluator.EvaluatorBuilder.Constant(ConstantExpression c)
 at IQToolkit.ExpressionEvaluator.EvaluatorBuilder.Build(Expression exp)
 at IQToolkit.ExpressionEvaluator.EvaluatorBuilder.MemberAccess(MemberExpression mLebensmittel Loaded

The first Expression is going through without a problem. The second will lead to the stacktrace above (the first query will not be executed in this example, but works if commented in).

DataServiceQuery<LebensmittelConsumed> lebQuery = (DataServiceQuery<LebensmittelConsumed>)
      from o in model.LebensmittelConsumedMenge
      select o;

   DataServiceQuery<LebensmittelConsumed> lebQuery2 = (DataServiceQuery<LebensmittelConsumed>)
      from o in model.LebensmittelConsumedMenge
      where o.Mahlzeit==mahlzeit
      select o;
   Debug.WriteLine("Expression:" + lebQuery.Expression);
   Debug.WriteLine("Expression2:" + lebQuery2.Expression);
 

3 Answers Found

 

Answer 1

Hi Shailan,

 The linq  interpreter on the phone  doesn't support closures on local variables, which means that using a variable inside a linq query  would cause runtime failures.
 This is an unfortunate bug and the only way to work  around this is to build the query in a string  and use the Execute<T> api to run the query.

 Here's a sample application which does this : 

http://blogs.msdn.com/b/phaniraj/archive/2010/03/19/developing-a-windows-phone-7-application-that-consumes-odata.aspx

 

Answer 2

Ok, understand, thx for the answer.

So you contruct the query-URL yourself and do the BeginExecute to fill in the data  from the service if I understand correctly.
Not as easy and nice as just throwing off a linq  request.

Is it planned to get this fixed either on the OData service or on the phones LinQ interpreter? Hope so as its working perfectly on SL already...

 

 

 

Answer 3

Any word on how close we are to having a fix for this? I'm writing a lot of extra code with conditional symbols that I'm looking forward to throwing out.
 
 
 

<< Previous      Next >>


Microsoft   |   Windows   |   Visual Studio   |   Follow us on Twitter