This project has moved and is read-only. For the latest updates, please go here.

Getting started with complex Linq Queries

Dec 5, 2010 at 11:45 AM

I try to port my SilverlightPhoneDatabase Project over to Sterling and now I am encountering some starting issues.

How could I do something like that:

                linqMovies.ItemsSource = from o in DbAccess.Db.Table<ExerciseViewModel>()
                                         orderby o.Name
                                         group o by o.Type.Name into c
                                         orderby c.Key
                                         select new PublicGrouping<string, ExerciseViewModel>(c);
with Sterling?
My first step was to create an Index over the Name and create a query like this:

linqMovies.ItemsSource = from o in DatabaseService.Current.Database.Query<ExerciseViewModel, String, Guid>(PhoneDatabase.NAME)
                                         orderby o.Index
                                         select new ExerciseViewModel(o.LazyValue.Value)
But of cause that has no grouping over the Type.Name property inside.
Can I do some kind of "full table search" for some properties without creating an index for everything?
Dec 5, 2010 at 3:23 PM

The phone doesn't support the IQueryable so it returns the IEnumerable which doesn't support the more advanced functions. Best case is to cast to a List and then perform operations on the list you can otherwise perform on the phone.

You can do a full table scan by iterating the index and access the LazyValue.Value and querying that - each time that property is accessed it will deserialize the full class from isolated storage and you will be able to query any other fields from there.

Dec 5, 2010 at 5:08 PM

Thx. That worked. The groupby works now as a charm - even if it might involve creating a complete in memory list. But that has to be done anyways-

Another problem you might help out - as I am not sure how the system is working here.

For example:

class a
observableCollection<b> liste;

class b

It seems that the b objects are stored in the database table b, when I store the objects for "a". Is that correct?

But the deserialisation of a will somehow lead to an empty a.liste collection. Is the sub-object not retrieved/stored? How would I do that? Store only the b-related e a.liste objects?



Dec 5, 2010 at 9:47 PM

Solved it. It was a mistake by me, that the data in the referenced list a.liste was not there.

Good that the system takes care if I .Load(a) I will get automatically the list of a retrieved - even if its not stored as a tree (as far as I understand).