Question

I'm trying to create an app for Windows Phone 8 that displays data in a LongListSelector that's populated from a SQL CE database that's shipped with the app. I think I have the opening and reading from the database functions down, but I can't correctly use LINQ to SQL to group the data for the LLS.

I've got a database class with a table and corresponding columns. I'm using a helper class "KeyedList" to add a public name for the data from msdn sample code:

public class KeyedList<TKey, TItem> : List<TItem>
{
    public TKey Key { protected set; get; }

    public KeyedList(TKey key, IEnumerable<TItem> items)
        : base(items)
    {
        Key = key;
    }

    public KeyedList(IGrouping<TKey, TItem> grouping)
        : base(grouping)
    {
        Key = grouping.Key;
    }
} 

Then I've got my database context:

dB = new DataContext(DataContext.DBConnectionString);

Finally, here's the LINQ to SQL I'm trying to use:

var items =
            from item in dB.TableName
            orderby dB.ID
            group item by dB.Generation into generation
            select new <KeyedList<string,Item>(generation);

var allItems = new List<KeyedList<string, Item>>(items)

I've pretty much taken this code from the sample, but I can't get the grouping and ordering to work when creating allItems for binding to the LongListSelector. I keep getting invalid arguments error.

I'm very new at VB programming and appreciate all the help!

Was it helpful?

Solution

I found the issue. When creating the new Keyed list make sure to use the correct key type and item type. The key type will be the type of the data used by group by, and the item type is your DataContext. So in my case db.Generation is a string and the DataContext type is of type Item.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top